ios 4.0上的NSXMLParser内存泄漏 - **NOT**NSCFString

sch*_*one 1 memory iphone memory-leaks nsxmlparser

在我的NSXMLParser完成并从内存中释放后,我得到了一个奇怪的泄漏.

它提出了NSMapTable alloc leak.这是我的堆栈:

   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
Run Code Online (Sandbox Code Playgroud)

想法?

欣赏你可以流下的任何光!

这是代码:

[NSThread detachNewThreadSelector:@selector(parseXML:) 
                         toTarget:self 
                       withObject:requestStr];
Run Code Online (Sandbox Code Playgroud)

它在自己的线程上调用此方法:

- (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");
}
Run Code Online (Sandbox Code Playgroud)

小智 9

这可能为时已晚,但我发现了这个解决方案:

NSData * dataXml = [[NSData alloc] initWithContentsOfURL:url];
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:dataXml];
[dataXml release];
Run Code Online (Sandbox Code Playgroud)

代替

NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
Run Code Online (Sandbox Code Playgroud)

没有更多内存泄漏......