30-OCARC Basic Concepts Arm and MRC mixed

Source: Internet
Author: User

ARC

What's the principle of arc?

When arc is turned on, the compiler will automatically insert retain, release and autorelease where the code is appropriate, and as a program ape, there is no need to worry that the compiler will do the wrong thing (unless the developer himself uses the arc).

What are the advantages of arc?

Completely eliminates the cumbersome manual management of memory, allowing the program ape to focus more on the app's business

Basically to avoid memory leaks

It can sometimes be faster because the compiler can also perform some optimizations

What are the principles of arc? What is a strong pointer? What is a weak pointer?

As long as there is a strong pointer variable pointing to the object, the object remains in memory

1. Strong pointers

All pointer variables are strong pointers by default

A pointer modified by __strong

For example:

Person *P1 = [[Person alloc] init];

__strong person *p2 = [[Person alloc] init];

2. Weak pointers

A pointer modified by __weak

__weak person *p = [[Person alloc] init];

What are the @property modifiers under arc?

Strong: For OC objects, equivalent to retain in MRC

Weak: For OC objects, equivalent to assign in MRC

Assign: For basic data types, like the Assign in MRC

How the object is memory-managed in Arc

1.ARC under single object memory management

1) under ARC, all pointers are strong pointers

2) ARC, a object that wants to have a B object, then a strong pointer is needed to point to the B object

3) A object does not have a B object, nothing to do, the compiler will automatically help us do

2.ARC multi-Object memory management (strong, weak, assign)

Save an object in arc with strong, equivalent to the retain in MRC

@property (nonatomic, strong) Dog *dog;

In Arc if you save the object do not use assign, with weak

Assign is specifically used to save the base data type if the object is saved with weak

@property (nonatomic, weak) person *owner;

How arc solves circular reference problems

Arc and MRC, if A has B, B also has a, then a weak pointer must be used by one party

That means one end with strong, one end with weak

Arm and MRC Mixed

How is the non-ARC class compatible with ARC mode?

For:

Find Project->targets->bulid phases->compiles sources-> Find related files Right click on the right compiler flags add related code

Add one end code to the relevant file,

Change to non-ARC-FNO-OBJC-ARC

Converted to arc,-F-OBJC-ARC (not used)

MRC Turn Arc

How to manipulate Xcode to convert MRC to ARC

Edit->convert->to Objective ARC

30-OCARC Basic Concepts Arm and MRC mixed

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.