每个线程都需要自己的autorelease池吗? [英] Does every thread need its own autorelease pool?

查看:133
本文介绍了每个线程都需要自己的autorelease池吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个线程都有自己的池吗?我在写一个使用线程的iPhone应用程序。如果我不把一个池在一个线程,它抱怨泄漏。

Does every thread have to have its own pool? I am writing an iPhone app which uses threads. If I do not put a pool on a thread it complains abut leaking.

我想要做的是存储一些比线程更长的对象。

What I wanted to do was to store some object which outlives the thread. How can I do it?

推荐答案

不,每个 NSThread 自己 NSRunLoop ,但不是自己的 NSAutoreleasePool 。因此,你必须创建一个,如果你正在执行一个大型操作或一个需要大量时间的操作,你应该不时地 drain 池,以保持你的内存占用低。

No, every NSThread has its own NSRunLoop, but not its own NSAutoreleasePool. Thus you have to create one and if you are performing a large operation or a operation that needs a lot of time, you really should drain the pool from time to time to keep your memory footprint low.

对象存储根本不绑定到线程,您可以从每个线程访问每个对象,但是访问者可能对象不是线程安全的,因此杀死你的应用程序。但是,这取决于您的应用和代码,而不是线程。

Object storage isn't bound to a thread at all, you can access every object from every thread you want, but it is possible that the accessor to the object isn't threadsafe and thus kills your app. However, this depends on your app and your code and not on threads.

这篇关于每个线程都需要自己的autorelease池吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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