0
我正在做一些參考計數增加的工作。以下是示例。iOS - 參考計數問題
.h文件。
@property (nonatomic, retain) NSString *s1;
.m文件
@synthesize S1;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
s1 = [[NSString alloc] init];
NSLog(@"%d",[s1 retainCount]);
[s1 retain];
NSLog(@"%d",[s1 retainCount]);
[s1 copy];
NSLog(@"%d",[s1 retainCount]);
}
當我發現引用計數,它顯示爲-1所有這些,我這個有點糊塗了,請幫助我。
不要使用'retainCount'- http://stackoverflow.com/questions/4636146/when-to-use-retaincount/4636477#4636477 – Volker
只是強調:千萬不要使用retainCount。幫你一個忙,並開始使用ARC。 – gnasher729
[RetainCount在-1後可能是-1嗎?](http://stackoverflow.com/questions/16728133/retaincount-is-1-after-alloc) –