First of all, I wish my happy Birthday ~23 ~
The concept of a autorelease
Autorelease will treat an object instance as if it were a C-language automatic variable. When the scope (equivalent to a variable scope) is exceeded, an instance of the object's release strength method is called.
In addition, unlike the C language automatic variable, the programmer can set the scope of the variables themselves, that is, through the autoreleasepool to achieve.
The Autorelease method of invoking an object is to put the object nearest to a NSAutoreleasePool, the object's lifetime is equivalent to the scope of the C language variable. For all objects that call the Autorelease method, the release method is called when the auto-free pool is destroyed.
A typical application is in the Nsrunloop. When the observe hears the Runloop entry, it creates an auto-release pool that destroys the auto-free pool and re-creates a new auto-release pool before the Runloop enters hibernation. An auto-release pool is also destroyed when Runloop exits this way, you can avoid out-of-memory symptoms.
The other is that many of the class methods in the Cocoa framework also return autorelease objects, such as +array.
Realization of two Autorelease
Learn by GNUstep:
When calling the Autorelease method, internal is actually an instance method that invokes the currently used Autoreleasepool object
[Pool addobject:obj];
The method, in essence, is to add an object to the inner object array.
[Array AddObject];
The destruction of the automatic release pool is the Forin loop to find the OBJC of each array and let it call the release method.
2016-2-Arc Knowledge Summary (two autorelease concepts and implementation)