Dark Horse programmer --- autorelease method, dark horse --- autorelease
------ Java training, Android training, iOS training, and. Net training. We look forward to communicating with you! ------- Basic usage; 1. The autorelease method returns the object itself. 2. After the autorelease method is called, the counter of the object remains unchanged. 2. autorelease puts the object in an automatic release pool. 3, when the automatic release pool is destroyed, it will perform a release operation autorelease on all objects in the pool: 1. No need to worry about the time objects are released 2. No need to worry about when to call release autorelease. Note: 1. Do not use autorelease for objects that occupy a large amount of memory; 2> using autorelease for objects that consume less memory does not have much impact. incorrect syntax: 1. Calling autorelease after alloc, also called release @ autoreleasepool {Person * p = [[[Person alloc] init] autorelease] [p release];} 2. autorelease @ autoreleasepool {Person * p = [[[Person alloc] init] autorelease] release]} automatically released the pool multiple times in a row. 1. When the IOS program is running, there will be countless pools created. These pools all exist in the stack structure (Advanced and later) 2. When an object calls the autorelease method, this object will be placed in the release pool at the top of the stack to automatically release the pool. Creation Method: 1, before IOS5.0: NSAID utoreleasepool * pool = [[NSAID utoreleasepool alloc] init]; [pool release]; // [pool drain]; 2> Start With IOS5.0 @ autoreleasepool {} 1. The methods provided by the system do not contain alloc, new, and copy. The returned objects are autorelease, for example, NSString * s = @ "adaf"; 2. Some class methods are often provided during development. Do not directly use the class name to create an object that has been autorelisted, generally, self + (id) person {return [[[self alloc] init] autorelease];} int main () is used () {@ autoreleasepool // you must add a pool {Person * p = [[Person alloc] init] autorelease] ;}} to streamline the Person statement in the create class method: + (id) person {return [[Person alloc] init] autorelease];}