Advertise Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Your First iPhone App
($1.99)

iPhone Code Generator
($9.99)

Infinote Pinboard
for Todos and Notes
(free)

picplz
(free)

poG
($2.99)

VintageChart+
by Wine Spectator
(free)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-09-2008, 01:46 AM   #1 (permalink)
Registered Member
 
Marco's Avatar
 
Join Date: Apr 2008
Posts: 62
Default 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.
__________________
Peace in Christ
Marco Napoli
http://www.ourlovingmother.org
Marco is offline   Reply With Quote
Old 10-09-2008, 11:17 AM   #2 (permalink)
Registered Member
 
Join Date: Aug 2008
Posts: 246
Default

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"
bikr is offline   Reply With Quote
Old 10-09-2008, 01:09 PM   #3 (permalink)
Registered Member
 
Marco's Avatar
 
Join Date: Apr 2008
Posts: 62
Default

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
__________________
Peace in Christ
Marco Napoli
http://www.ourlovingmother.org
Marco is offline   Reply With Quote
Old 10-09-2008, 01:16 PM   #4 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 211
Default

Maybe NSXMLParser is using pool'd memory. Try wrapping an NSAutoreleasePool around your NSXMLParser.
lapse is offline   Reply With Quote
Old 10-09-2008, 01:47 PM   #5 (permalink)
Registered Member
 
Marco's Avatar
 
Join Date: Apr 2008
Posts: 62
Default

Yep I tried using the NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; and it still leaks memory there, weird.
__________________
Peace in Christ
Marco Napoli
http://www.ourlovingmother.org
Marco is offline   Reply With Quote
Old 10-09-2008, 02:28 PM   #6 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 211
Default

Why are you releasing xmlURL? It's not created by you.
lapse is offline   Reply With Quote
Old 10-09-2008, 06:48 PM   #7 (permalink)
Registered Member
 
Marco's Avatar
 
Join Date: Apr 2008
Posts: 62
Default

I was trying to release everything to see if I could get it to stop leaking...

So I should not be releasing the xmlURL?
__________________
Peace in Christ
Marco Napoli
http://www.ourlovingmother.org
Marco is offline   Reply With Quote
Old 10-09-2008, 06:54 PM   #8 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 211
Default

No because it is not alloc'd by you.
lapse is offline   Reply With Quote
Old 01-06-2009, 08:00 AM   #9 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 22
Default

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.
ichi is offline   Reply With Quote
Old 07-28-2009, 01:55 PM   #10 (permalink)
New Member
 
Join Date: Jul 2009
Posts: 1
Unhappy

Quote:
Originally Posted by ichi View Post
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...
RomainL is offline   Reply With Quote
Old 03-04-2010, 04:05 AM   #11 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 4
Default

From what I understand from this page, this is an Apple bug. Hopefully it'll be resolved soon.
sani212 is offline   Reply With Quote
Reply

Bookmarks

Tags
nsxmlparser

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


» Advertisements
» Stats
Members: 52,419
Threads: 53,155
Posts: 226,643
Top Poster: BrianSlick (3,598)
Welcome to our newest member, Iar
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:55 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0