当我的NSXMLParser完成并从内存中释放后,我得到了一个奇怪的泄漏。ios 4.0上的NSXMLParser内存泄漏 - ** NOT ** NSCFString
它出现了NSMapTable的alloc泄漏。这是我的堆栈:
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
想法?
欣赏任何光线,你可以摆脱!
下面的代码:
[NSThread detachNewThreadSelector:@selector(parseXML:)
toTarget:self
withObject:requestStr];
其自身的线程调用此方法:
- (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");
}
你能显示一些代码吗?它有点难以从错误信息中反转你的代码。特别是在您创建NSXMLParser的地方,很高兴看到 – 2010-08-02 01:54:31
schone:使用此代码更新您的原始问题,而不是将其粘贴为评论。 – iwasrobbed 2010-08-02 02:12:19
这是一个解决方法:http://blog.filipekberg.se/2010/11/30/nsxmlparser-has-memory-leaks-in-ios-4/ – 2010-11-30 14:33:48