NSAutoReleasePool文档摘抄
2014-04-14 10:49
381 查看
自动释放池永远只能在与创建时所在的上下文相同的上下文中被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是否处于多线程模式。
自动释放池只能“内联”式使用。我们永远没有任何理由将一个自动释放池的实例作为一个类的成员变量。
如果你释放了一个不在栈顶的自动释放池,这会导致栈中位于这个池之上的所有未被释放的自动释放池被释放。
另外:
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是否处于多线程模式。
相关文章推荐
- NSAutoreleasePool与autorelease 详解(二)
- NSAutoreleasePool的release和drain的区别
- NSAutoreleasePool与内存管理
- __NSAutoreleaseNoPool(): ... utoreleased with no pool in place - just leaking
- 了解Objective-C中NSAutoreleasePool使用方法
- @autoreleasepool 代替 NSAutoreleasepool
- NSAutoreleasePool自动释放池
- Foundation框架常用数据类型和NSAutoreleasePool自动释放池解析
- __NSAutoreleaseNoPool(): ... utoreleased with no pool in place - just leaking
- NSAutoReleasePool使用中drain和release的区别
- nsautoreleasepool研究
- NSAutoReleasePool使用中drain和release的区别
- Xcode中使用NSAutoreleasePool报错的问题
- NSAutoReleasePool 用法
- iPhone中objective-c NSAutoreleasePool 的一些理解
- NSAutoReleasePool使用中drain和release的区别
- NSAutoreleasepool
- ojbect-c中,NSAutoreleasePool
- Objective-C NSAutoreleasePool
- NSAutoreleasePool & thread