I am new to iPhone programming, and am running my app against the Leaks tool in Instruments. The tool is finding a few leaks, all of which seem to point to 1 line of code in a class which uses NSXMLParser:
- (BOOL)parse{
NSURL *url = [[NSURL alloc] initWithString:@"[url here]"];
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
NSLog(@"NSXMLParser initialized");
[parser parse];
[url release];
[parser release];
return YES;
}
The tool points to the line creating the parser as having the leak:
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
Can anyone point me in the right direction on this one? I've been going through reference counts in my code for an hour now with no luck.
UPDATE:
Ok, taking the suggestions from 2 answers, I added these lines before creating the NSURL:
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
And I added this line right before releasing the parser:
[parser setDelegate:nil];
Each addition reduced the number of leaks, and now I'm down to 2. One points to CFNetwork and one points to Foundation as the responsible library. Examining the call stack on both doesn't show any of my code at all.
Is there anything else I might be doing wrong here?