这里是我的代码奇怪保留新创建的字符串对象的数量
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *str = [[NSString alloc]initWithString:@"This is string object"];
NSLog(@"%lu", [str retainCount]);
[pool drain];
return 0;
}
我预计输出为1 becase的是新创建的对象,但结果是1152921504606846. 这里有什么问题?
请勿使用retainCount。请参阅 - [何时使用-retainCount?](http://stackoverflow.com/questions/4636146/when-to-use-retaincount) – beryllium 2012-02-01 11:59:51
可能重复的[NSString保留计数](http://stackoverflow.com/questions/1390334/nsstring-retain-count) – 2012-02-01 15:05:13