tags:

views:

16

answers:

1

hi friends.. i got the memory leak in following code segment when i ran my app with instrument..

-(void)connectionDidFinishLoading:conn{
//[self.conn release];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:myData];
[xmlParser setDelegate:self];
[xmlParser parse];
[xmlParser release];

}

but i couldnt make out exactly where leak is happening.. Any suggestions

A: 

Release myData after you initiate the parser (only if it is not an autorelease object):

NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:myData];
[myData release];

Also, you are allocating an NSXMLParser object. You can autorelease it:

NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:myData];

But that might release the parser object before you are done using it.

So you might want to manually release it after the parsing is complete, in which case you'll probably have to declare it in .h file.

lukya