问题
之前被问到两个问题
- Autorelease Pool 中有什么对象?
- Autorelease Pool 中的对象在什么时候释放?
之前对这两个问题不是很确定,查了点资料,其中苹果文档中有这样一段
In a reference-counted environment (as opposed to one which uses garbage collection), an NSAutoreleasePool object contains objects that have received an autorelease message and when drained it sends a release message to each of those objects. Thus, sending autorelease instead of release to an object extends the lifetime of that object at least until the pool itself is drained (it may be longer if the object is subsequently retained). An object can be put into the same pool several times, in which case it receives a release message for each time it was put into the pool.
文档中说的很明确,在引用计数环境中(而不是垃圾回收机选)Autorelease Pool 中包含了收到 autorelease
消息的对象,并在 「倾倒」 Autorelease Pool 的时候,给其中的每个对象发送 release
消息。