【问题标题】:Detatching threads and ARC under iOS 5: how to make compatible code with 4.3?iOS 5下分离线程和ARC:如何使代码与4.3兼容?
【发布时间】:2011-11-11 19:12:33
【问题描述】:

所以,我在代码中找到了一个分离线程的位置,它运行良好。

在我在 iOS 4.3 上运行代码之前,它会出现数十亿“NSCFString 类的对象 0x1045660 自动释放而没有适当的池 - 只是泄漏”错误。

但是我不能在线程调用的方法中放置一个自动释放池,因为当 ARC 开启时,NSAutoReleasePool 不能使用。

那么,怎么办?

【问题讨论】:

  • 没有@autorelease 指令什么的吗?在这里只是一个疯狂的刺伤。

标签: objective-c ios xcode cocoa-touch automatic-ref-counting


【解决方案1】:

将其括在@autoreleasepool { }

【讨论】:

  • 对我来说,同样的错误正在发生。正如你所说,我将代码放入 @autoreleasepool { while(1) { [NSThread detachNewThreadSelector:@selector(updateCountdown) toTarget:self withObject:nil]; [NSThread sleepForTimeInterval:1.0]; } }
【解决方案2】:

你不能把你的代码用 @autorelease { // 你的代码在这里 } ?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多