views:

1823

answers:

4
A: 

How did you declare rssParser? Is it just a pointer or is it a property? If its a property, how is it declared?

caahab
Only other reference I have in my code is in the .h.No properties set or synthesize. @interface TestAppDelegate : NSObject <UIApplicationDelegate> { NSXMLParser *rssParser;}
Lee Armstrong
To your screenshot, you should release first and then set to nil. Thats leaking definitly
caahab
Your TestAppDelegate should also inherit from the NSXMLParserDelegate protocol. If this class handles the events from the parser.
caahab
+2  A: 

The most likely cause is that one of your delegate methods retains the parser. Do you do anything with your parser parameter in the delegate methods?

Do you get a leak every time you refresh?

If this is the only place that rssParser is used, why are you making it an ivar? If you do need an ivar, I cannot stress enough how important it is to always use accessors for them and never access them directly. The single best way to avoid memory leaks is to use accessors for your ivars.

Also, never release something without immediately setting it to something else (usually nil). Your release of rssParser above is a crash waiting to happen because you now have a pointer to potentially unallocated memory.

Rob Napier
Yes I do get a leak every time, I have made the changes you describe as yes it shouldn't be an ivar! Still leaky!
Lee Armstrong
Do you have Xcode 3.2 (from SnowLeopard)? The Build and Analyze tool is very good at finding simple leaks.
Rob Napier
Yeah I already tried that.
Lee Armstrong
Have added a screenshot of instruments....
Lee Armstrong
Poking around the boards, this may be a caching issue with either NSURLConnection or NSXMLParser. You may want to open a radar on this. Google "nsxmlparser leak". http://www.iphonedevsdk.com/forum/iphone-sdk-development/4910-nsxmlparser-rssparser-causing-memory-leak.htmlhttp://stackoverflow.com/questions/555623/got-memory-leak-problem-when-i-used-nsxmlparser-same-as-seismicxml-example
Rob Napier
Thanks Rob. When you say open a radar. Is that a bug report with Apple?
Lee Armstrong
Correct. bugreport.apple.com From the stories I've heard from Apple folks, they named the original internal server that housed this stuff "radar" because by keeping track of all the bugs, it was supposed to give people almost psychic knowledge of new problems, like Radar in MASH. But this may just be Cupertino legend. CocoaDev claims it just means "it's on Apple's radar," but provide even less authority than my flimsy "from Apple folks." But I still prefer the first story. In any case, internal links to BugReporter use the URL scheme rdar://, and are widely known as "radars."
Rob Napier
A: 

Seems this is a well know problem. See here NSURLConnection leaking. However if you set the following before initializing the parser leaking stops:

[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
NSXMLParser *parser = [[NSXMLParser alloc]initWithContentsOfURL:URL];
Colins
Actually Apple got back to me and this issue is already logged as 6469143. Not sure when they will fix it though. Still leaks changing to your way of doing it too!
Lee Armstrong
+6  A: 

Apple have got back to me and this is a bug #6469143

Looks like they plan to fix for 4.0

Lee Armstrong
Have you had any reply from Apple about this Bug?
Louis Russell
I am getting the same leak did this leak fixed in 4.0
kiri
Well I still see it in the iOS4 SDK. I haven't yet downloaded the latest
Phil Nash
@Phil I downloaded SDK 4.0.1 and I am still having an issue. But, I could be dumb.
Dustin Scaggs