views:

177

answers:

2

Hello,

I'm getting a weird leak in my NSXMLParser after it's done and released from memory.

It comes up with NSMapTable alloc leak. Here's my stack:

   0 libSystem.B.dylib calloc
   1 libobjc.A.dylib _internal_class_createInstanceFromZone
   2 libobjc.A.dylib class_createInstance
   3 Foundation NSAllocateObject
   4 Foundation +[NSMapTable alloc] <===== this is the leak...
   5 Foundation -[NSXMLParser initWithData:]
   6 Foundation -[NSXMLParser initWithContentsOfURL:]
   7 idispatch -[RootViewController parseXML:] /Developer/iPhone  Apps/iDispatch/Classes/RootViewController.m:562 <================== this is my code calling
   8 Foundation -[NSThread main]
   9 Foundation __NSThread__main__
  10 libSystem.B.dylib _pthread_start
  11 libSystem.B.dylib thread_start

Ideas?

Appreciate any light you can shed!

Here's the code:

[NSThread detachNewThreadSelector:@selector(parseXML:) 
                         toTarget:self 
                       withObject:requestStr];

which calls this method on its own thread:

- (void)parseXML:(NSString*)theURL {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:theURL]];
    DLog(@"URL: %@",theURL);
    [parser setDelegate:self];

    [parser parse];

    [parser release];

    [pool release];
    DLog(@"xml parser thread end and released");
}
A: 

You should reset the delegate before releasing ([parser setDelegate:nil])

Anders K.
still getting that same leak and also getting two extra small ones saying Malloc 512 bytes at frame [allocateCollectableUnscannedStorage]ideas?
schone
have you tried without the pool, just to see if there is a diff?
Anders K.
ya it crashes saying i'm trying to spawn a thread without its own pool.... it doesn't like me when i do that :)
schone
I also have another app i'm working on, just in its begining stage without a saperate thread for the NSXMLParser in which i load the parser in viewDidLoad just becuz i'm in the initial testing and and building my parser and it's giving me the same leak.This one is done on the main thread.
schone
Anyone? I'm new here, does this mean no one has any further ideas to try to tackle?
schone
A: 

Same problem here. The leak appears even if I'm just to this:

NSURL *xmlURL = [NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"myfile.xml"]]; 
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[parser release];

I've reported the bug to apple, since it seems a serious bug in the NSXMLParser class.

noda
Thanks for putting in your answer. I was getting kind of worried that I'm really not getting something fundamental and it keeps on appearing in all my apps that use NSXMLParser.
schone