引用计数相关.md

2017-03-15  本文已影响9人  CoderLNHui

释放对象后的retainCount值

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSObject *object = [[NSObject alloc] init];
    NSLog(@"Reference Count = %u", [object retainCount]);
    [object release];
    NSLog(@"Reference Count = %u", [object retainCount]);
    return YES;
}
Reference Count = 1
Reference Count = 1

因为该对象的内存已经被回收,而我们向一个已经被回收的对象发了一个 retainCount 消息,所以它的输出结果应该是不确定的,如果该对象所占的内存被复用了,那么就有可能造成程序异常崩溃.

上一篇下一篇

猜你喜欢

热点阅读