Copy and retain:
1. Copy actually creates the same object, but retain is not;
2. Copy is content copy, and retain is Pointer copy;
3. copy is a copy of the content. For nsstring, it does. But what if copy is an nsarray? In this case, only the pointer pointing to the corresponding element in the array is copied. This is called "Shallow copy ".
4. Copy: nsstring * newpt = [PT copy];
In this case, a memory segment will be re-opened on the stack to store @ "ABC". For example, if 0x1122 is @ "ABC, a space such as the address will be allocated to newpt on the stack: the content of 0 xaacc is 0x1122. Therefore, retaincount is increased by 1 for newpt to manage the memory segment 0x1122;
Assign and retain:
1. Assign: simple assignment without changing the index count;
2. Assign: nsstring * newpt = [PT assing];
At this time, the addresses of newpt and PT are completely the same. The content of 0 xaaaa is 0x1111, that is, newpt is only the alias of Pt. For any operation, it is equal to another operation. Therefore, retaincount does not need to be added;
3. Assign is a direct value assignment;
4. Retain uses the reference count. Retain increases the reference count by 1. Release reduces the reference count by 1. When the reference count is 0, the dealloc function is called and the memory is recycled;
5. Retain: nsstring * newpt = [PT retain];
At this time, the newpt address is no longer 0 xaaaa, which may be 0 xaabb but the content is still 0x1111. Therefore, both newpt and Pt can manage the memory where "ABC" is located, so retaincount needs to be increased by 1;
Readonly:
1. the attribute is read-only and the default tag is read/write. If you specify read-only, you only need one reader in @ implementation. Or if you use the @ synthesize keyword, the reader method is parsed.
Readwrite:
1. the attribute is read/write, which is also the default attribute. Both the configurator and reader must be implemented in @ implementation. If the @ synthesize keyword is used, the reader and the setter will be parsed;
Nonatomic:
1. Non-atomic access. No lock is applied to attribute assignment. Concurrent multi-threaded access improves performance. If this attribute is not added, both access methods are atomic transaction access by default;
Weak and strong property (difference between strong reference and weak reference ):
1. the weak and strong attributes are required only when you open the Arc. In this case, you cannot use the retain release autorelease operation because the arc will automatically perform these operations for you, however, you need to use weak and strong on the object attributes, where strong is equivalent to the retain attribute, while weak is equivalent to assign.
2. You only need to use weak (strong by default) to avoid retain cycles (that is, the parent class contains subclass {parent class retain's subclass }, the sub-class also calls the parent class {sub-class and retain the parent class}, so it cannot be release)
3. the pointer declared as weak. Once the address pointed to by the pointer is released, these pointers will be assigned as nil. This benefit effectively prevents wild pointers.
ARC (automatic reference counting ):
1. Retain/release is automatically added to the Code. The Code to be manually added to handle the reference count for memory management can be automatically completed by the compiler.
This function starts importing iOS 5/Mac OS X 10.7 and can be used after xcode4.2.
Usage of strong, weak, and copy:
1. For details, iboutlet can be weak, nsstring is copy, and delegate is generally weak. Generally, the "internal" attribute of the class is set to strong, and the "external" attribute of the class is set to weak. In the end, it is a matter of authority. The memory cannot be released due to cyclic reference.
2. There will be a lot of retian without using arc.
3. If you write @ synthesize abc = _ ABC;, the system automatically declares an _ ABC instance variable.
Use assign: for basic data types (nsinteger) and C data types (INT, float, double, Char, etc)
Use copy: To nsstring
Use retain: for other nsobject and its subclass
This article from "Zhou weibin" blog, please be sure to keep this source http://wilbin.blog.51cto.com/9259255/1538973