7

我正在尝试在 4.3.5 中将 NSThreads 与 ARC 一起使用。使用 iOS 5 一切正常,但如果我在 4.3 等较旧的 iOS 上尝试它,它就会泄漏。通常我会为 NSThreads 使用 Autoreleasepool 但由于 ARC 中没有手动 Autoreleasepool 我不知道如何解决这个问题。

启动线程后,我在控制台中收到大量消息,例如“__NSAutoreleaseNoPool(): NSComparisonPredicate 类的对象 0x4567b40 自动释放而没有适当的池 - 只是泄漏”。

NSThread detachNewThreadSelector:@selector(showAlert) toTarget:self withObject:nil];

如何正确使用 ARC 和 iOS 5.0 之前的线程。

干杯nettz

4

1 回答 1

19
-(void)showAlert
{
    @autoreleasepool {
        // Your code.
    }
}
于 2011-08-22T15:01:46.743 回答