代码:
NSObject *obj = [[NSObject alloc] init];
NSLog(@"retain count 1:%d",obj.retainCount);
[obj retain];
NSLog(@"retain count 2:%d",obj.retainCount);
[obj release];
NSLog(@"retain count 3:%d",obj.retainCount);
[obj release];
NSLog(@"retain count 4:%d",obj.retainCount);
[obj release];
NSLog(@"retain count 5:%d",obj.retainCount);
[obj release];
NSLog(@"retain count 6:%d",obj.retainCount);
程序会crash到第三个release,但是retain count 4:打印出来是1,为什么?
NSObject *obj = [[NSObject alloc] init];
NSLog(@"retain count 1:%d",obj.retainCount);
[obj retain];
NSLog(@"retain count 2:%d",obj.retainCount);
[obj release];
NSLog(@"retain count 3:%d",obj.retainCount);
[obj release];
NSLog(@"retain count 4:%d",obj.retainCount);
[obj release];
NSLog(@"retain count 5:%d",obj.retainCount);
[obj release];
NSLog(@"retain count 6:%d",obj.retainCount);
程序会crash到第三个release,但是retain count 4:打印出来是1,为什么?