NSAutoReleasePool文档摘抄

自动释放池永远只能在与创建时所在的上下文相同的上下文中被drain,这里所说的上下文指的是一个函数中或者一个run loop体中。

自动释放池只能“内联”式使用。我们永远没有任何理由将一个自动释放池的实例作为一个类的成员变量。

如果你释放了一个不在栈顶的自动释放池,这会导致栈中位于这个池之上的所有未被释放的自动释放池被释放。

另外:

If you neglect to send release to an autorelease pool when you are finished with it (something not recommended), it is released when one of the autorelease pools in which it nests is released.

This behavior has implications for exceptional conditions. If an exception occurs, and the thread suddenly transfers out of the current context, the pool associated with that context is released. However, if that pool is not the top pool on the thread’s stack, all the pools above the released pool are also released (releasing all their objects in the process). The top autorelease pool on the thread’s stack then becomes the pool previously underneath the released pool associated with the exceptional condition. Because of this behavior, exception handlers do not need to release objects that were sent autorelease. Neither is it necessary or even desirable for an exception handler to send release to its autorelease pool, unless the handler is re-raising the exception.

 

在Non-AppKit Programs中,简单的创建autoreleasepool即可

如果使用POSIX thread APIs来创建线程,那么我们不可以使用cocoa(包括autoreleasepool),除非cocoa处于多线程模式,开启cocoa的多线程模式,必须至少创建一个nsthread,所以,我们可以创建一个nsthread然后立即exit它。我们可以使用nsthread类的isMultiThreaded函数来检测cocoa是否处于多线程模式。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值