在运行我的线程一段时间后,Instruments显示__NSDate已稳步加入其#号活动值。线程中的iOS内存泄漏
我的结论是,这踩不分配物体。但是,这一行会导致编译错误NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
如何强制此线程保留其所有对象,或者如何使用工作ARC创建合适的线程。
- (void) start {
NSThread* myThread = [[NSThread alloc] initWithTarget:self
selector:@selector(myThreadMainRoutine)
object:nil];
[myThread start]; // Actually create the thread
}
- (void)myThreadMainRoutine {
// stuff inits here ...
// Do thread work here.
while (_live) {
// do some stuff ...
[runLoop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.05]];
[NSThread sleepForTimeInterval:0.05f];
}
// clean stuff here ...
}
谢谢,我把它的内部,而循环,怎么样代码前,在此之后,我将有整体功能和第二autoreleasepool我while循环中的一个autoreleasepool块? – michael
@michael:我最后的评论其实是错的,你需要两个池。我已经相应地更新了答案。 –