GDataXML Leaks

I’ve started using GDataXML for almost all of my iPhone XML needs, but I quickly noticed that after a few refreshes my project was leaking thousands of strings and this was unacceptable.  Almost 1MB of leaked strings after 5 refreshes.  To curb this, write this wrap your GDataXML code in a NSAutoReleasePool block (you might have to change some NSAutoReleasePools to blocks within the GData code as well)

NSMutableArray* posts = [[NSMutableArray alloc] init];
@autoreleasepool {
   GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:responseData options:0 error:nil];
   NSArray *documentArray = [doc.rootElement elementsForName:@"Comic"];
   for (GDataXMLElement *element in documentArray) {
     //Do something...
     NewPost* post = [[NewPost alloc] init];
     //Set post up...
     [posts addObject:post];
     [post release],post=nil;
   [doc release],doc=nil;
//_posts is a NSArray instance variable, setting it to nil before setting it releases all of the objects in it.
_posts = nil;
_posts = posts;

Leave a Reply


captcha *