【发布时间】:2010-12-07 05:51:25
【问题描述】:
Objective-C 中最简单的代码会导致奇怪的行为:
#import Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSObject *obj = [[NSObject alloc] init];
NSLog(@"retain count %d",[obj retainCount]);//print 1
[obj release];//obj deallocated
NSLog(@"retain count %d",[obj retainCount]); //still printing 1 in Snow Leopard! Why??
[pool drain];
return 0;
}
第二个NSLog() 应该打印“消息retainCount sent to freed object=0x103eb0”。
如果您使用 Leopard,一切正常,但在 Snow Leopard 中,第二个 NSLog 仍会打印 1。
这是雪豹版 Xcode 中的错误吗?
【问题讨论】:
标签: objective-c cocoa memory-management