iOS assign, copy, retain

Source: Internet
Author: User

Assign : simple assignment, without changing the index count (Reference counting).

Copy : Create an object with an index count of 1 and then release the old object

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

  ( nsinteger cgfloat c int, float, double,         char,  et cetera)

Use Copy : to nsstring

Use retain : for other NSObject and its subclasses

nonatomic , non-atomic access, no synchronization, and multi-threaded concurrent access can improve performance. Note that if you do not add this property, the default is two access methods are atomic transaction Access

1.readonly indicates that this property is read-only and is generated only Getter method is not generated Setter method.

2.readwrite , set the available access level

3.retain , which indicates that the property is assigned a value, first Release before assigning a new value to the property, the reference is added 1 .

4.nonatomic , non-atomic access, no synchronization, and multi-threaded concurrent access can improve performance. Note that if you do not add this property, the default is two access methods are atomic transaction access.

copy a and b When a piece of memory is shared, it is used. a Span style= "line-height:normal;font-family:times;" >b each has its own memory.

5. Atomic and nonatomic used to determine the getter and setter generated by the compiler is an atomic operation. In a multithreaded environment, atomic operations are necessary, otherwise they may cause incorrect results

Assign and the retain the Difference

Assignis directly assigned, which may cause1the problem when the data isint, floatwhen native types are used, you can use theAssign. retainJust as2reference counts are used, as described inretaincauses the reference count to be added1, Releasecauses the reference count to be reduced1, when the reference count is0when theDeallocthe function is called and the memory is recycled.


This article is from the "11204872" blog, please be sure to keep this source http://11214872.blog.51cto.com/11204872/1754487

iOS assign, copy, retain

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.