Working principle of ARC

Source: Internet
Author: User

 

 

What is ARC?

Automatic Reference Counting, the Automatic Reference Counting, that is, ARC, is the biggest change and most exciting change introduced by WWDC2011 and iOS5.

 

ARC will automatically help you add retain and release/autorelease statements.

 

 

ARC compilers are divided into (1) Front-end compilers (2) Optimizers

 
(1) Front-end compiler-insert a corresponding release statement for each "owned" object. ---- An object is created in a method. The front-end compiler will automatically add the release statement at the end of the method to destroy it. ---- Objects (instance variables/attributes) owned by the class are released in the dealloc Method

 

(2) ARC optimizer-when multiple repeated calls to retain and release appear in the Code, the ARC optimizer is responsible for removing redundant retain and release statements.

 

 

 

 

 

If you want to hold an object, send a retain to it. If you don't use this object any more, you need to send a release (or autorealse) to it, mutable copy or new call (automatic reference count + 1), one call of release or autorealse (automatic reference count-1 ).

 

 

 


 

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.