Strong, weak, retain, assign, copy, nonmatic, retainnonmatic

Source: Internet
Author: User

Strong, weak, retain, assign, copy, nonmatic, retainnonmatic

Assign: simple assignment, without changing the index count (Reference Counting) to the basic data class

Copy: Create an object with an index count of 1 and release the old object. For NSString

Retain: Release the old object, assign the value of the old object to the input object, and increase the index count of the input object to 1.

Difference between weak and strong:

The difference between weak and strong is that when an object no longer has a pointer of the strong type pointing to it, it will be released, even if there is a weak pointer pointing to it. Once the last strong pointer leaves, the object will be released and all remaining weak pointers will be cleared.

Differences between copy and retain:

Copy actually creates the same object, but retain is not;

Copy is content copy, and retain is Pointer copy;

Copy is a copy of the content. For NSString, if NSArray is copied, only the pointer pointing to the corresponding element in the array is copied. This is called "Shallow copy ".

Differences between _ block and _ weak Modifiers

_ Block can be used in both ARC and MRC modes. It can modify objects and basic data types.

_ Weak can only be used in ARC mode, and can only modify the object (NSString). It cannot modify the basic data type (int ).

The _ block object can be assigned a value again in the block, __weak is not allowed.

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.