您好,我正在使用 [NSThread detachNewThreadSelector:toTarget:withObject:] 并且我遇到了很多内存泄漏,因为我没有为分离线程设置自动释放池。我只是想知道我实际上在哪里做这个?是不是在我打电话之前
[NSThread detachNewThreadSelector:toTarget:withObject:]
或者在另一个线程中运行的方法中?
任何帮助将不胜感激,一些示例代码会很棒。
谢谢。
最佳答案
在你用线程调用的方法中......即给定这个......
[NSThread detachNewThreadSelector:@selector(doStuff) toTarget:self withObject:nil];
你的方法是...
- (void)doStuff {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//Do stuff
[pool release];
}
关于iphone - 使用 [NSThread detachNewThreadSelector :toTarget:withObject:] 时如何设置自动释放池,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5350174/