Dark Horse programmer --- autorelease method, dark horse --- autorelease

Source: Internet
Author: User

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];}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.