The difference between strong,weak,retain,assign,copy nomatic and so on
Copy and retain:
1, copy is actually the establishment of a same object, and retain is not;
2, copy is a copy of the content, retain is a pointer copy;
3, copy is the content of the copy, for like NSString, it is true, but if copy is a Nsarray it? This is just a copy of the pointer to the corresponding element in the array. This is called "shallow copy".
4, copy of the situation: NSString *NEWPT = [pt copy];
At this time will re-open a memory on the heap storage @ "ABC" such as 0x1122 content is @ "ABC will also be on the stack for the NEWPT allocation of space such as address: 0XAACC content is 0x1122 so Retaincount added 1 for NEWPT to manage 0x1122 this memory;
Assign and retain:
1, assign: Simple assignment, do not change the index count;
2, assign situation: NSString *NEWPT = [pt assing]; At this point NEWPT and PT are exactly the same address is 0XAAAA content 0x1111 that is newpt only PT alias, for any one operation is equal to another operation, so retaincount do not need to increase;3, assign is directly assigned value;
4, retain uses the reference count, retain causes the reference count plus 1, release causes the reference count minus 1, when the reference count is 0 o'clock, the Dealloc function is called, memory is recycled;5, retain situation: nsstring *NEWPT = [pt retain]; At this point the address of NEWPT is no longer 0Xaaaa and may be 0Xaabb but the content is still 0x1111. So both NEWPT and PT can manage the memory of "ABC", so the retaincount needs to be increased by 1; ReadOnly:
1, the property is read-only, the default tag is read-write, if you specify read-only, only one reader is required in @implementation. Or if you use the @synthesize keyword, there is also a reader method that is parsed ReadWrite:
1, the Description property will be read and write, this is the default property. Both the setup and the reader need to be implemented in @implementation. If you use the @synthesize keyword, both the reader and the setup are parsed; Nonatomic:
1, non-atomic access, the value of the property is not locked, multi-threaded concurrent access will improve performance. If this attribute is not added, the default is two access methods are atomic transaction access; weak and strong property (the difference between strong and weak references):
1, weak and strong properties are only required when you open arc, and you cannot use retain release autorelease because ARC will do it for you automatically, but you need to use weak and strong on object properties , where strong is equivalent to the Retain attribute, and weak is equivalent to assign.
2, only one situation you need to use weak (the default is strong), is to avoid retain cycles (that is, the parent class has a subclass {The parent class retain the child class}, the child class is called the parent class {subclass and retain the parent class}, which cannot be release)
3, the pointer is declared as weak, the pointer points to the address once released, these pointers will be assigned to nil. Such a benefit can effectively prevent the wild hands. ARC (Automatic Reference counting):
1, the code is automatically added to the Retain/release, the original need to manually add the reference count to handle memory management of the code can be automatically completed by the compiler. This function is started in IOS 5/mac OS X 10.7 and can be used later with Xcode4.2.
Strong,weak,copy Specific usage:
1. Specific point: Iboutlet can be weak,nsstring for copy,delegate General for the weak, others see the situation. In general, the properties of the class "internal" are set to strong, and the properties of the class "external" are set to weak. In the end it is a question of attribution. Be careful that circular references cause memory to fail to release.
2. You will see a lot of Retian without arc.
3. If you write @synthesize ABC = _ABC, then the system automatically helps you to declare a _ABC instance variable.
Using assign: for underlying data types (Nsinteger) and C data types (int, float, double, char, etc.)
Using copy: On NSString
Use retain: For other nsobject and its subclasses
ReadWrite,readonly,assign,retain,copy,nonatomic properties function
@property is a property access declaration that supports several properties within the extension:
1,getter=gettername,setter=settername, set the method name of setter and getter
2,readwrite,readonly, setting the available access level
The 2,assign,setter method is assigned directly, without any retain operation, in order to solve the problem of the original type and the circular reference
3,retain,setter method to release old values of parameters and then retain new values, all implementations are in this order (CC has relevant information)
4,copy,setter method copy operation, as with the retain process, the old value of release, and then copy the new object, Retaincount is 1. This is the mechanism introduced to reduce dependency on the context.
Copy is used when you don't want a and b to share a piece of memory. A and B each have their own memory.
5,nonatomic, non-atomic access, no synchronization, multi-threaded concurrent access improves performance. Note that if you do not add this property, the default is two access methods are atomic transaction access. The lock is added to the owning object instance level (as I understand ...).
Atomic and nonatomic are used to determine whether the compiler-generated getter and setter are atomic operations. In a multithreaded environment, atomic operations are necessary, otherwise they may cause incorrect results.
Respect for the original, address: http://zhangmingwei.iteye.com/blog/1748431
The difference and function of iOS development strong,weak,retain,assign,copy nomatic etc.