This question already has an answer here:
- When to use -retainCount? 11 answers
NSString* nsString=[[NSString alloc]initWithString:@"nsString"];
NSLog(@"nsString RetainCount:%li",[nsString retainCount]);
the corresponding result is:
2013-03-04 11:18:03.291 ARC[655:303] nsString RetainCount:-1
in addition: if use init a NSMutableString instance; it return 1;
http://whentouseretaincount.com
Immutable
NSStrings
generated at compile time are singletons. Thus, they don't do theretain/release
dance at all.NSString
detects when it is initialized with such and just returns the string directly. You'd find that the object returned byalloc
in that code is different than the one returned by theinit...
call.