 |
 |
|
 |
10-09-2008, 02:46 AM
|
#1 (permalink)
|
|
New Member
Join Date: Apr 2008
Posts: 56
|
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, 12:17 PM
|
#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, 02:09 PM
|
#3 (permalink)
|
|
New Member
Join Date: Apr 2008
Posts: 56
|
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, 02: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, 02:47 PM
|
#5 (permalink)
|
|
New Member
Join Date: Apr 2008
Posts: 56
|
Yep I tried using the NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; and it still leaks memory there, weird.
|
|
|
10-09-2008, 03: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, 07:48 PM
|
#7 (permalink)
|
|
New Member
Join Date: Apr 2008
Posts: 56
|
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, 07:54 PM
|
#8 (permalink)
|
|
New Member
Join Date: Aug 2008
Posts: 211
|
No because it is not alloc'd by you.
|
|
|
01-06-2009, 09: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 07:10 PM.
|
|
|
07-28-2009, 02: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...
|
|
|
 |
| 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: 587 |
| 46 members and 541 guests |
| applezinga, blacksheep_2011, chinhminhdo, CHV, cordoprod, danny8, dany88, dcinqc, Dynno, ELA, Forsworn, Gandolf, guelinator, introiboad, issya, Janek2004, jbro, jhoncybpr, john3478, jschorn, Kalimba, kilobytedump, lifeCoder45, loobian, marciokoko, Mopedhead, Mr Jack, msudan, nathanp, noberasco, nycos, ovidiu, P2k, pereorra, RayKreisel, sascha, SmallWonder, supudo, svveet, totoro81, toughturtle, vcanic, wolfenberg, _Mac |
| Most users ever online was 779, 05-11-2009 at 10:55 AM. |
» Stats |
Members: 21,483
Threads: 35,768
Posts: 156,679
Top Poster: smasher (2,448)
|
| Welcome to our newest member, guelinator |
|