问题描述
我有一段时间没有注意到我的控制台输出,我突然发现很多奇怪的错误。
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的特定字词是():
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):
所以我更正了我的例子。可以说,这个具体问题与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没有池到位 - 只是泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!