ARC mechanism, arc

Source: Internet
Author: User

ARC mechanism, arc
I. Basic Introduction

  • ARC is a new feature added since iOS 5, completely eliminating the hassle of manual memory management. The compiler will automatically insert appropriate retain, release, and autorelease statements in appropriate places. You no longer need to worry about memory management, because the compiler handles everything for you.
  • ARC is a compiler feature, not a runtime feature of iOS. It is not similar to the garbage collector in other languages. Therefore, the performance of ARC is the same as that of manual memory management, and sometimes it can be faster, because the compiler can also execute some optimizations.
Ii. Basic Principles 1. Rules

The ARC rule is very simple: as long as there is a strong pointer variable pointing to the object, the object will remain in the memory

2. Strong pointers and weak pointers
  • By default, all instance variables and local variables are Strong pointers.
  • After the objects pointed to by the weak pointer are recycled, the weak pointer will automatically change to the nil pointer without triggering a wild pointer error.
Iii. Usage notes
  • Release, retain, autorelease, and retainCount cannot be called.
  • You can override dealloc, but cannot call [super dealloc].
  • @ Property: If you want to have an object for a long time, use strong and weak for other objects.
  • Other basic data types still use assign
  • When the two ends reference each other, one end uses strong and the other end uses weak

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.