现在我有了一个ClassA : NSObject
,然后在 viewcontrollerviewDidLoad
中,查看下面的代码:
- (void)viewDidLoad {
ClassA *a = [[ClassA alloc] init];
NSLog(@"a retainCount = %d", [a retainCount]);
ClassA *b = a;
NSLog(@"a retainCount = %d b retainCount= %d ", [a retainCount],[b retainCount]);
[a release];
NSLog(@"a retainCount = %d b retainCount= %d", [a retainCount],[b retainCount]);
[super viewDidLoad];
}
控制台输出如下所示:
2012-11-02 14:43:35.437 RetainCountTest[1043:207] a retainCount = 1
2012-11-02 14:43:35.439 RetainCountTest[1043:207] a retainCount = 1 b retainCount= 1
2012-11-02 14:43:35.439 RetainCountTest[1043:207] a retainCount = 1 b retainCount= 1
我不明白,当我打电话时[a release]
,为什么[a retainCount]== 1
?</p>