The auto-free pool is implemented as a stack: When you create a new auto-free pool, it is added to the top of the stack. The object that receives the Autorelease message is placed in the topmost auto-free pool. If you put an object into an auto-free pool and then create a new auto-free pool and then destroy the newly created auto-free pool, the auto-free object will still exist because the auto-free pool that holds the object still exists.
What is an auto-free pool
1. Autorelease Pool
The Autorelease pool is an automatic memory recovery mechanism for OC, which can release some temporary variables through the automatic release pools recovery. Automatically release the pool when it's destroyed, all the objects in the pool do a release operation.
2, Autorelease
Any OC object that calls the Autorelease method will place the object in its closest auto-release pool (the release pool at the top of the stack).
How to create an auto-free pool
ios5.0 New Way
@autoreleasepool {}
The old way before ios5.0
NSAutoreleasePool *pool=[[nsautoreleasepool Alloc]init]; [Pool release];
The auto-free pool is implemented as a stack: When you create a new auto-free pool, it is added to the top of the stack. The object that receives the Autorelease message is placed in the topmost auto-free pool. If you put an object into an auto-free pool and then create a new auto-free pool and then destroy the newly created auto-free pool, the auto-free object will still exist because the auto-free pool that holds the object still exists.
-
Top
-
0
iOS Auto-free pool