gpt4 book ai didi

iphone - __NSAutoreleaseNoPool() : Object 0x753c2f0 of class General autoreleased with no pool in place - just leaking

转载 作者:太空狗 更新时间:2023-10-30 03:46:50 25 4
gpt4 key购买 nike

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

__NSAutoreleaseNoPool():General 类的对象 0x753c2f0 自动释放,没有适当的池 - 只是泄漏

__NSAutoreleaseNoPool(): 类 __NSArrayM 的对象 0x753c300 自动释放,没有适当的池 - 只是泄漏

我不知道这是哪里发生的?

编辑..

我用这个

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

有了 statupStuff 我就有了

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

错误发生在 refreshDBData 方法中的代码之后不久。

最佳答案

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

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

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

[pool drain]; //see comment below
}

补充:下面的 Richard 指出 drain 比 release 更可取,以承认(在桌面上,尚未在 iOS 上)您可能正在运行垃圾收集器。苹果的具体说法是(source):

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 有关,目前该设备上没有垃圾收集。因此,原发帖人属于“排水与释放具有相同效果”的阵营,而不是“排水……必要时触发垃圾收集;然而,释放是无操作”的阵营。

关于iphone - __NSAutoreleaseNoPool() : Object 0x753c2f0 of class General autoreleased with no pool in place - just leaking,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4313122/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com