问题
Possible Duplicate:
NSString retain Count
Is it possible that any object has its retain count in negative value ?
I have this code
NSString *str = [[NSString alloc] initWithString:@"Hello World"];
NSLog(@"String Retain Count: %i", [str retainCount]);
this will return the retain count -1.
Why this happened ?
also I have done like this
NSString *str = [[NSString alloc] init]
still its return negative value in retain count.
How this is happening ?
Please help to understand this thing!!!!!
回答1:
retainCount doesn't return the reference count of an object. - it returns unrelated nonsense.
(For performance reasons, immutable constant strings, when copied, return self
. If you compare the pointer to @""
and [[NSString alloc] initWithString:@""]
, they will be equal.)
来源:https://stackoverflow.com/questions/14601270/why-retain-count-in-negative-value