views:

14

answers:

0

I've asked this before but never got a clear answer, I think perhaps I was asking the wrong questions or maybe not clarifying my question so I'll try again.

I have an app that needs to retrieve menu items, product details etc. from a server. I have the data retriever / parser as a separate object that I create when needed. I release it when it is done (through a method that is called when the parsing is complete since the fetch is asynchronous) but Build & Analyze tells me there is a leak.

My question is, should I be immediately releasing the object after I call it's function or should I release it when the asynchronous fetch & parse is finished?

Code is as follows (just the relevant bits because it's pages long):

(In Calling object)

// Create parser object and tell it to get titles
NavigationParser *navigationParserObject = [[NavigationParser alloc] initWithDelegate:self];
[navigationParserObject getNavigationOfParentId:1];

(In navigation parser object)

*SOAP message created*
// Create connection & initialise webData
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

// Successfully got data, parse & release connection and webData buffer
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
  *Response dumped to terminal, parser set up etc.*
  [xmlParser parse];
  [xmlParser release];
  [webData release];
  [connection release];

// Finished parsing the document
-(void)parserDidEndDocument:(NSXMLParser *)parser
  *(Saves relevant parsed data, does error checking etc.)*

  // Inform caller that XML data has been fetched & parsed
  [delegate navigationDataTransferComplete:(NavigationParser *)self];

(In Calling object)
-(void)navigationDataTransferComplete:(NavigationParser *)navigationParserObject
  *Display data or error message, remove "Please Wait" screen etc.*
  // Get rid of parser
  [navigationParserObject release];

The bits in between asterisks are just summaries of what happened so far in the function. My question is, should the parser object rather be released immediately after the call

[navigationParserObject getNavigationOfParentId:1];

as opposed to in the method it calls when the parsing is complete? It seems that is what Clang is saying.