OC Syntax -- ask the specific difference between copy and retain in NSString attribute declaration, nsstringretain

Source: Internet
Author: User

OC Syntax -- ask the specific difference between copy and retain in NSString attribute declaration, nsstringretain
Ask the specific difference between copy and retain in NSString attribute declaration. copy is to release the source object, and then copy the new object to the source object.
Retain is to release the source object and then the new object retain is then paid to the source object
The fundamental difference is that when the object performs deep copy, the copy operation should open up a new storage space, and the shortest time of the shortest copy is the same. In terms of reference count, retain adds 1 to the reference count of the source object.
The reference count of the source object is increased by 1 in the case of shallow replication, the reference count of the source object remains unchanged in the case of deep replication, and the reference count of the new object is increased by 1.

NSString * str = @ "hello ";

// Copy the original copy mode

NSMutableString * strM = [str copy];

// [StrM appendString: @ "123"]; it cannot run because copy is copied as is and the memory address is the same. I can't think that another type points to him. He is the same thing.

Deep replication: to change

Light replication: UNCHANGED

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.