尝试弹出未知的自动释放池 [英] Attempt to pop an unknown autorelease pool

查看:102
本文介绍了尝试弹出未知的自动释放池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道这个错误是什么意思?
***尝试弹出未知的自动释放池

Does anyone know what this error means? *** attempt to pop an unknown autorelease pool

我在我的应用程序中看到这个在NSOperationQueue中使用NSOperations。每个操作都有自己的Autorelease池。由于每个操作都解析xml并将信息推送到Core Data,我定期排空我的自动释放池并重新创建它。如果我不排出池,我没有看到这些错误。

I am seeing this in my app that uses NSOperations in NSOperationQueue. Each operation has it's own Autorelease pool. Since each operation is parsing xml and pushing information into Core Data, I periodically 'drain' my autorelease pool and re-create it. If I don't drain the pool, I don't see these errors.

更新:
这是我的代码:

UPDATE: Here's my code:

在我的NSOperation的主体中,我分配池并将其分配给一个assign属性,如下所示:

In the main of my NSOperation, I alloc the pool and assign it to an 'assign' property like this:

self.downloadAndParsePool = [[NSAutoreleasePool alloc] init];

在我的主发布结束时,它像这样:

at the end of my main I release it like this:

[self.downloadAndParsePool release];
self.downloadAndParsePool = nil;

如果操作做了很多解析和插入Core Data,它会定期调用我的drain方法:

If the operation does a lot of parsing and inserting into Core Data, it will call my drain method periodically:

- (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];
    }
}


推荐答案

似乎问题是由漏洞被调用的方法外分配池的事实,即使在同一个线程。这里是NSAutoreleasePool类引用说。

It seems that the issue is caused by the fact that the drain is called outside of the method that allocated the pool even if on the same thread. Here is what NSAutoreleasePool Class Reference says.


你应该在同一上下文中调用一个自动释放

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.

您看到的消息是

[self.downloadAndParsePool drain];

注意:XMLPerformance示例应用程序使用相同的模式定期排空池。它自iOS4.0起也产生此消息

NOTE: XMLPerformance sample app uses the same pattern of periodically draining the pool. It also produces this message since iOS4.0

这篇关于尝试弹出未知的自动释放池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆