“自动释放没有水池到位”是什么意思? [英] What does “Autoreleased with no pool in place” mean?

查看:189
本文介绍了“自动释放没有水池到位”是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序结构如下,
的核心部分是使用C ++编写的,并且使用线程很重要,而我正在Objective C中开发UI,
如果我不执行线程工作正常,但我无法禁用,停止线程,UI在日志中随机崩溃我可以看到,以下消息

My Application structure is as follows, the core part is written in C++ and using thread heavily, and i am developing UI in Objective C on top of it, if i don't execute the thread it works fine, but i can't disable, stop thread, UI is crashing randomly in the log i could see , following message

__NSAutoreleaseNoPool(): Object 0x350270 of class NSCFString autoreleased with no pool in place - just leaking

类似消息越来越多,
通过谷歌来知道,我需要设置NSAutoReleasePool来摆脱它,但是如何将其与C ++代码集成在一起。

Similar messages coming more then once, by googling come to know, i need to set NSAutoReleasePool to get rid of it, but how its possible to integrate the same with C++ code.

编辑:核心库将从UI激活,因此我想,安全地说UI正在主线程中运行,Lib是创建/终止线程而不通知UI,在这种情况下
,我可以在UI中调用AutoReleasePool

Core lib will be activated from UI , hence i suppose, its safe to say UI is running in the main thread, Lib is creating/terminating thread without notifying UI, in this case, can i call AutoReleasePool in the UI

任何人都可以指导我吗?

Can anyone guide me?

推荐答案

请参阅这些文档,了解有关Cocoa的多线程的内容: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html

See these docs for what you should know about multithreading with Cocoa: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html

可以像你一样设计你的应用程序,但应该记住两件事:

It's OK to design your app like you have, but two things should be kept in mind:


  1. 当在主线程上操作UI控件(如AppKit或UIKit)时,生活是最简单的(有时需要)。您可以在后台线程上使用Foundation对象和一些AppKit / UIKit对象,并且可以在多个线程中使用一些Foundation对象。

  2. 如果您在后台线程中使用任何Cocoa对象,您需要在这些线程上设置自动释放池。

像这样:

- (void)backgroundThreadStart 
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    // do stuff

    [pool release];
}

这将修复您的控制台错误,但您可能还有其他问题导致你看到的实际崩溃。

That will fix your console errors, but you might have other issues that led to the actual crashing you were seeing.

这篇关于“自动释放没有水池到位”是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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