NSString * string = @ "origion";
NSString * stringCopy = [string copy];
NSLog (@ "stringCopy RC =% lu", [stringCopy retainCount])
Print results: stringCopy RC = 18446744073709551615
The above code is coming from the Internet copy, online analysis that RC = 2;
Who can explain why not 2 it? In addition, the output string with NSLog reference count and stringCopy same.
I use Xcode 4.6.
Reply:
You put this NSLog (@ "stringCopy RC =% lu", [stringCopy retainCount]) into NSLog (@ "stringCopy RC =% i", [stringCopy retainCount]) look
Reply:
Because the point is a constant string @ "origion" string, the reference count is random
Reply:
Normally we do not need to specifically check an object's retain count is. Results of the query are often unexpected. Other objects you do not know the inside of the framework of the object you're interested in how many retain operation. In the debug memory management problems, you ensure that your code as long as concerns compliance with owner rules.
String constants are usually in constant pool, not in the heap memory. So long as alloc, new, copy the corresponding release like. Do not need to know his retaincount.
Reply:
+1
Reply:
Thank you for your answer.
No comments:
Post a Comment