Possible Duplicate:
When to use -retainCount?




我试图了解自动释放池。我创建了一个示例应用程序,如下所示:

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSString *releasePoolString = [[[NSString alloc] initWithFormat:@"%@",@"ReleasePool autorelease variable"] autorelease];

NSLog(@"Retain count of autorelease variable inside release pool %i",[releasePoolString retainCount]);

[pool drain];

// After pool drain still retain count = 1 ??????
NSLog(@"Retain count of autorelease variable after release pool drain %i",[releasePoolString retainCount]);


最后一条日志仍将保留计数打印为1。
我错过了什么吗?有人可以帮助我了解...吗?

谢谢...

最佳答案

keepCount永远不会达到0,因为当它为1并调用release时,它将立即调用dealloc而不递减keepCount

07-28 06:24