有人知道这个错误是什么意思吗? *** 尝试弹出未知的自动释放池
我在使用 NSOperationQueue 中的 NSOperations 的应用程序中看到了这一点。每个操作都有它自己的自动释放池。由于每个操作都会解析 xml 并将信息推送到 Core Data,因此我会定期“耗尽”自动释放池并重新创建它。如果我不排空池中的水,我就不会看到这些错误。
更新: 这是我的代码:
在我的 NSOperation 的主体中,我分配池并将其分配给“分配”属性,如下所示:
self.downloadAndParsePool = [[NSAutoreleasePool alloc] init];
在我的主程序结束时,我像这样发布它:
[self.downloadAndParsePool release];
self.downloadAndParsePool = nil;
如果该操作进行了大量解析并插入到 Core Data 中,它将定期调用我的排出方法:
- (void) drainAutoreleasePool
{
// drain and re-create autorelease pool...this method is called periodically to keep memory down during parsing of large trees
if (self.downloadAndParsePool)
{
[self.downloadAndParsePool drain];
self.downloadAndParsePool = [[NSAutoreleasePool alloc] init];
}
}
最佳答案
这个问题似乎是由于在分配池的方法之外调用了 Drain 造成的,即使在同一线程上也是如此。这是 NSAutoreleasePool 类引用的内容。
You should always drain an autorelease pool in the same context (invocation of a method or function, or body of a loop) that it was created.
您看到的消息是由您调用rainAutoreleasePool中的drain触发的:
[self.downloadAndParsePool drain];
注意:XMLPerformance 示例应用程序使用相同的定期耗尽池的模式。从iOS4.0开始它也会产生这个消息
关于iphone - 尝试弹出未知的自动释放池,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3088978/