加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – __NSAutoreleaseNoPool():类General的对象0x753c2f0

发布时间:2020-12-14 19:35:38 所属栏目:百科 来源:网络整理
导读:我有一段时间没有注意到我的控制台输出,我突然发现很多奇怪的错误. __NSAutoreleaseNoPool():对象0x753c2f0类通用自动释放没有池到位 – 只是泄漏 __NSAutoreleaseNoPool():类__NSArrayM的对象0x753c300自动释放,没有池到位 – 只是泄漏 我不知道这发生了
我有一段时间没有注意到我的控制台输出,我突然发现很多奇怪的错误.

__NSAutoreleaseNoPool():对象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下面指出排水是优先释放以承认(在桌面上,还没有在iOS上)你可能正在运行垃圾收集器. Apple的特定词是(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有关,目前该设备上没有垃圾收集.因此,原始海报在“排水与释放效果相同”的阵营中,而不是“排水……如有必要,则触发垃圾收集;然而,释放是一个无操作”阵营.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读