ReadWrite: is a readable and writable feature that requires the generation of getter and setter methods;
ReadOnly is a property of all, only the Getter method is generated, does not generate setter methods, do not want attributes to be changed outside the class to use;
Reference count for a 1retain object after the Alloc object is allocated +1
Copy an object into a new object (new memory address) reference count of 1 original object count unchanged
Assign: is an assignment attribute, the setter method assigns the passed parameter to the instance variable (a key, in the same way), and is used for the underlying data type;
Weak: The properties of the object variable introduced by arc, a function more than assign, the object disappears after the pointer is nil, avoid the wild pointer (not a null pointer, is a pointer to "garbage" memory (not available memory);
Retain: Indicates holding characteristics, setter method will pass in the parameters first retained, after assignment (two keys, respectively in and out), the parameters of the Retaincount plus 1;
Strong:arc Introduction, equivalent to retain;
Copy: Represents an Assignment attribute, in which the setter method copies the incoming object; When a new object is required (two sets of houses, two keys);
Nonatomic: Non-atomic operation, determines whether the compiler generates setter and getter methods for atomic operation, no synchronization, multi-threaded access improves performance,
__unsafe_unretain: Object reference does not add 1, object is released, will not be set to nil, may cause wild pointers, try to use less.
Autorelease: Object reference count-1 if 0 is not released immediately, released at the nearest pool
As an example:
NSString *HOUSEOFMM = [[NSString alloc] initwithstring: ' Three-room and two-hall ' with Van Gogh ';
The preceding section of code performs the following two actions:
1 Allocate a piece of memory on the heap for storing @ ' Van Gogh's three rooms and two halls ', for example: memory address for the 0x1111 content for the "three-room two halls of Van Gogh",
2 Allocate a piece of memory on the stack to store Houseforwife, for example: 0XAAAA content is naturally 0x1111
See below (assign,retain,copy):
1.assign Case: NSString * myhouse = [HOUSEOFMM assign];
At this point Myhouse and HOUSEOFMM are exactly the same, the address is 0XAAAA, the content is 0x1111, that is, Myhouse is only houseofmm alias, for any one operation is equal to another operation. Therefore Retaincount does not need to increase. (The same in the same, the relationship is good, a key, give me Hold)
2.retain Case: NSString * myhouse = [houseofmm retain];
At this point, the address of Myhouse is no longer 0XAAAA and may be 0XAABB, but the content remains 0x1111. So myhouse and HOUSEOFMM can manage the memory of the "three rooms and two halls of Van Gogh". So the retaincount needs to be increased by 1. (some independent, each in and out, two keys)
3.copy Case: NSString * myhouse = [houseofmm copy];
At this time will be on the heap to re-open a memory storage @ ' installed in the three-room two hall, such as 0x1122, the content is @ ' in the three-room two halls ', at the same time will be on the stack for the Myhouse allocation of space, such as address: 0XAACC, the content of 0x1122, So Retaincount added 1 for myhouse to manage the memory of 0x1122. (two sets @ ' The three-room two halls of Van Gogh ', the condition is good, separated, the house one person, so the key one person. )
When to use assign, of course, is the House of Broken, Lite house pull
Underlying type (simple type, atomic type): Nsinteger,cgpoint,cgfloat,c data type (INT,FLOAT,DOUBLE,CHAR, etc.)
When to use copy
Classes containing mutable subclasses of deep copy, such as Nsarray,nsset,nsdictionary,nsdata, nscharacterset,nsindexset,nsstring
(A house that can be copied in depth)
But nsmutablearray this can not, mutable can not use copy, otherwise initialization will have a problem. Remember
When to use retain?
Other NSObject and their sub-objects well (most)
The strong in arc is the equivalent of a non-arc retain,arc, and it's strong to get a more key later.
Refer to this:
http://blog.csdn.net/favormm/article/details/7023322
http://www.crifan.com/object_c_property_setter_assign_retain_copy_weak_strong/
http://www.crifan.com/object_c_property_setter_assign_retain_copy_weak_strong/
iOS Learning Note-retain/assign/strong/weak/copy/mutablecopy/autorelease differences