Copy retain for deep and shallow copies and NSString

Source: Internet
Author: User

A shallow copy is like a reference type, while a deep copy is a value type, for example.

A shallow copy is a source object that is shared with a copy object, and only refers to a variable (with a different name). Changes to any of these objects affect the other object. For example, a person at the beginning of the call Zhang San, later renamed John Doe, but still the same person, whether it is Zhang three missing arms or legs or Li four short legs, is this person unlucky.

Deep copy means that the source and copy objects are independent of each other, and any changes to the object do not affect the other object. For example, a person named Zhang San, later with his cloning (assuming the law allows) another person, called John Doe, whether it is Zhang three short arms or legs or Li four lack of arms and legs will not affect another person. A typical value object, such as a predefined type int32,double, and a struct (struct), enumeration (enum), and so on.

NSString copy and retain is a typical deep copy and shallow copy of the distinction, retain just increase the reference count, any reference to the source data may cause the source data changes, and copy is to create a new copy object, the source data will not be modified.

Copy retain for deep and shallow copies and NSString

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.