10-09-2008, 01:46 AM
#1 (permalink )
Registered Member
Join Date: Apr 2008
Posts: 62
NSXMLParser *rssParser is causing a memory leak.
I have been trying to figure out why the NSXMLParser *rssParser is causing a memory leak. I have commented out all of my code and I believe this line is causing it. I am trying to parse a webservice using NSXMLParser, maybe I need to use something else?
Code:
- (void)parseXMLFileAtURL:(NSString *)URL
{
NSMutableArray * messageCountArray = [[NSMutableArray alloc] init];
NSURL *xmlURL = [NSURL URLWithString:URL];
NSXMLParser *rssParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL]; // causes leak, I believe
[messageCountArray release];
[xmlURL release];
[rssParser release];
}
I have also used Instruments with Apple's SeismicXML example and it also shows a leak.
Any ideas and help are appreciated.
10-09-2008, 11:17 AM
#2 (permalink )
Registered Member
Join Date: Aug 2008
Posts: 246
The only leak I see happening in seismic is when you click a row and safari is launched. My thought, without even looking at the code, is that the NSString they build for the url of the click isn't released because the app terminates to launch safari.. Just a hunch..
__________________
RPSOnline - Online Rock Paper Scissors!!
*Updates*
2.0 is "For Sale"
3.0 is "In Development"
10-09-2008, 01:09 PM
#3 (permalink )
Registered Member
Join Date: Apr 2008
Posts: 62
Thanks for your help.
I just cannot figure out how why this line causes a leak, even when I release right after?
NSXMLParser *rssParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
Marco
10-09-2008, 01:16 PM
#4 (permalink )
New Member
Join Date: Aug 2008
Posts: 211
Maybe NSXMLParser is using pool'd memory. Try wrapping an NSAutoreleasePool around your NSXMLParser.
10-09-2008, 01:47 PM
#5 (permalink )
Registered Member
Join Date: Apr 2008
Posts: 62
Yep I tried using the NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; and it still leaks memory there, weird.
10-09-2008, 02:28 PM
#6 (permalink )
New Member
Join Date: Aug 2008
Posts: 211
Why are you releasing xmlURL? It's not created by you.
10-09-2008, 06:48 PM
#7 (permalink )
Registered Member
Join Date: Apr 2008
Posts: 62
I was trying to release everything to see if I could get it to stop leaking...
So I should not be releasing the xmlURL?
10-09-2008, 06:54 PM
#8 (permalink )
New Member
Join Date: Aug 2008
Posts: 211
No because it is not alloc'd by you.
01-06-2009, 08:00 AM
#9 (permalink )
New Member
Join Date: Aug 2008
Posts: 22
I had this problem and it was doing my head in...
If I did this it like this (using NSData to load the file)
Code:
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"index.xml"];
NSData *xml = [NSData dataWithContentsOfFile:path];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:xml];
Then it didn't leak, but if I did this (loading it from an URL)...
Code:
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
It leaked (small, but still annoying).
I found a post that said if you put this before you init the xmlParser, then it stops it leaking and it worked for me...
Code:
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
I hope that helps someone else, as I've spent hours trying to figure that out...
Last edited by ichi; 01-16-2009 at 06:10 PM .
07-28-2009, 01:55 PM
#10 (permalink )
New Member
Join Date: Jul 2009
Posts: 1
Quote:
Originally Posted by
ichi
I had this problem and it was doing my head in...
If I did this it like this (using NSData to load the file)
Code:
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"index.xml"];
NSData *xml = [NSData dataWithContentsOfFile:path];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:xml];
Then it didn't leak, but if I did this (loading it from an URL)...
Code:
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
It leaked (small, but still annoying).
I found a post that said if you put this before you init the xmlParser, then it stops it leaking and it worked for me...
Code:
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
I hope that helps someone else, as I've spent hours trying to figure that out...
Unfortunately, my NSXMLParser is leaking, even when putting those 2 lines of cache configuration. I was using initWithData anyway, and calling initWithContentsOfURL didn't change anything. Don't know what to do then...
03-04-2010, 04:05 AM
#11 (permalink )
Registered Member
Join Date: Jan 2010
Posts: 4
From what I understand from this
page , this is an Apple bug. Hopefully it'll be resolved soon.
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Online Users: 470
39 members and 431 guests
abrown1 , BrianSlick , bujka , car91auto , Coolio098 , crunkstar , Dan the Man , DrCronus , Duncan C , dylanreich , EpicApps , firebug , gerard4sawyer , gtyt38 , Harpreet Bedi , hawaiian_punch , HemiMG , Iar , jbro , JeanNoel , jemimacoll , jmiller145 , JuanMazuera , MediaChicken , meleader2 , monoxgas , naturan1985 , newshidcom , nickleneck , preiss , reddertw , roland36graves , rTicker , Son of a Beach , TapTouchClick , theblob9 , thomas02 , tobiasglencr
Most users ever online was 965, 06-30-2010 at 04:26 AM.
» Stats
Members: 52,419
Threads: 53,155
Posts: 226,643
Top Poster: BrianSlick (3,598)
Welcome to our newest member, Iar