为什么在取消分配后,Objective-C对象仍然存在? [英] Why do Objective-C objects still exist after they are dealloced?

查看:57
本文介绍了为什么在取消分配后,Objective-C对象仍然存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有此代码...

I have this code here...

#import <Foundation/Foundation.h>
#import "Chip.h"

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    Chip *chip = [[Chip alloc] init];

    [chip release]; //Chip should be gone

    NSLog(@"%@", chip);

    [pool drain];
    return 0;
}

为什么在发行后仍然打印出芯片仍然给我描述.此时不应该将其删除吗?

Why does printing out the chip after it is released still gives me the description. Should it not be removed at this point?

推荐答案

chip 不见了.您只是在谈论它的幽灵.

chip is gone. You're just talking to its ghost.

添加用于记录呼叫的dealloc替代.您应该看到解除分配按预期发生.该对象已释放,但是没有其他任何事情会浪费内存,并且您的呼叫恰好不在擅自进入会造成麻烦的地方.

Add a dealloc override that logs the call. You should see that the deallocation occurs as expected. The object is released, but nothing else has happened to trash the memory and your call happens not to trespass where it would cause trouble.

这篇关于为什么在取消分配后,Objective-C对象仍然存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆