Monday, December 23, 2013
property of the three attributes. retain / copy / assign
NSString * pt = [[NSString alloc] initWithString: @ "abc"];
The above piece of code performs the following two actions
A section of memory allocated on the heap to store @ "abc" such as: memory address is: 0X1111 content "abc"
2 allocated on the stack memory used to store some pt example: address: 0Xaaaa content nature as 0X1111
The following were facie assign retain copy
assign the case: NSString * newPt = [pt assing];
At this point newPt and pt are identical addresses are 0Xaaaa content 0X1111 that newPt just pt aliases for any operation is equivalent to another operation. So retainCount need to increase.
cases retain the: NSString * newPt = [pt retain];
At this point newPt address is no longer 0Xaaaa, but the content is still possible to 0Xaabb is 0X1111. So newPt and pt can manage memory "abc" is located. Therefore, the need to increase 1
retainCountcopy of the case: NSString * newPt = [pt copy];
At this store will re-open a section of memory on the heap @ "abc" such 0X1122 content @ "abc simultaneously will allocate space on the stack such as newPt address: 0Xaacc content 0X1122 therefore retainCount by 1 for newPt to manage this memory 0X1122
Reply:
assign: simple assignment, do not change the index count
copy: the establishment of an index count of object 1, and then release the old object
retain: releasing the old object, given the value of the old object input object, and then increase the input object index count of 1
Reply:
The new sdk do not need their own release, retain the compiler to automatically resolve the
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment