__NSAutoreleaseNoPool():类常规自动释放的对象0x753c2f0没有池到位 - 只是泄漏 [英] __NSAutoreleaseNoPool(): Object 0x753c2f0 of class General autoreleased with no pool in place - just leaking

查看:113
本文介绍了__NSAutoreleaseNoPool():类常规自动释放的对象0x753c2f0没有池到位 - 只是泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段时间没有注意到我的控制台输出,我突然发现很多奇怪的错误。

I haven't noticed my console output for a while and I've suddenly noticed lots of weird errors.

__ NSAutoreleaseNoPool():类General的对象0x753c2f0已自动释放,没有池到位 - 只是泄漏

__ NSAutoreleaseNoPool():对象0x753c300类__NSArrayM自动释放,没有游泳池 - 只是泄漏

我不知道这是怎么发生的?

I've no idea where this happening?

编辑..

我用这个

[self performSelectorInBackground:@selector(startupStuff) withObject:sender];

使用 statupStuff 我有这个

General *rdb = [[General alloc] autorelease];
[rdb refreshDBData];

错误发生在 refreshDBData 方法。

推荐答案

自动释放池与线程相关联。如果通过performSelectorInBackground创建线程,则需要为自己创建和销毁自动释放池。所以你需要startupStuff看起来像这样:

Autorelease pools are tied to threads. If you create a thread through performSelectorInBackground then you need to create and destroy an autorelease pool for yourself. So you need startupStuff to look like this:

- (void)startupStuff:(id)sender
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    // ... everything else you were doing ...

    [pool drain]; //see comment below
}

另外:Richard在下面指出排水更可取要发布以确认(在桌面上,尚未在iOS上)您可能正在使用垃圾收集器运行。 Apple的特定字词是( source ):

Addition: Richard below makes the point that drain is preferable to release to acknowledge that (on the desktop, not yet on iOS) you may be running with a garbage collector. Apple's specific words are (source):


在垃圾收集环境中,向池中发送排放消息会在必要时触发垃圾回收;然而,释放是一种无操作。在参考计数环境中,排水与释放具有相同的效果。因此,通常情况下,你应该使用drain而不是release。

In a garbage-collected environment, sending a drain message to a pool triggers garbage collection if necessary; release, however, is a no-op. In a reference-counted environment, drain has the same effect as release. Typically, therefore, you should use drain instead of release.

所以我更正了我的例子。可以说,这个具体问题与iPhone有关,目前该设备上没有垃圾收集。因此,原始海报在排水与释放效果相同的阵营中,而不是排水......如有必要,会触发垃圾收集;然而,释放是一种无操作阵营。

So I've corrected my example. Suffice to say, this specific question is to do with the iPhone and currently there is no garbage collection on that device. So the originating poster is in the "drain has the same effect as release" camp, not the "drain ... triggers garbage collection if necessary; release, however, is a no-op" camp.

这篇关于__NSAutoreleaseNoPool():类常规自动释放的对象0x753c2f0没有池到位 - 只是泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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