我有以下代码:内存管理ios7
- (IBAction)HeyCount:(UIButton *)sender {
NSString* strr = [[NSString alloc] initWithString:@"hi there"];
self.string = @"789";
ohYeah = @"456";
NSLog(@"Retain Count of ohYeah:[%d] with String:[%ld]",[ohYeah retainCount],(long)[ohYeah integerValue]);
NSLog(@"Retain Count of strr:[%d] with String:[%ld]",[strr retainCount],(long)[strr integerValue]);
}
和OUT把上面的代码是:
Retain Count of ohYeah:[-1] with String:[456]
Retain Count of strr:[-1] with String:[0]
ohYeah的声明是在.h文件中
NSString * ohYeah;
我没有使用ARC
。你们谁能解释为什么retain count
的strings
是-1
并访问retain count
-1
不应该崩溃的对象?
不要使用保留计数 – Wain
http://whentouseretaincount.com – datwelk
我只使用保留计数来学习内存管理。 –