- (void)viewDidLoad {
[super viewDidLoad];
Person *person = [[Person alloc] init];
NSLog(@"%tu", person.retainCount); // 2015-12-31 09:57:31.003 01-引用计数练习[2014:46979] 1
Person *anotherPerson = [person retain];
NSLog(@"%tu", person.retainCount); // 2015-12-31 09:57:31.003 01-引用计数练习[2014:46979] 2
[anotherPerson release];
NSLog(@"%tu", person.retainCount); // 2015-12-31 09:57:31.003 01-引用计数练习[2014:46979] 1
//这次release完了以后 对象就被释放了, 但是retainCount仍然是1
[person release];
//为什么对象被释放了以后, 还能打印出他的类型
NSLog(@"%@", person); //2015-12-31 10:01:15.624 01-引用计数练习[2062:50220] <Person: 0x7fd84151e680>
}
那么问题来了....
为什么对象被释放了, 仍然能打印出来呢....
求解..
网友评论