当在dealloc中调用super是否重要? [英] Does it matter when super is called in dealloc?

查看:137
本文介绍了当在dealloc中调用super是否重要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

- (void)dealloc {
    [super dealloc];
    [receivedData release]; receivedData = nil;
}

- (void)dealloc {
    [receivedData release]; receivedData = nil;
    [super dealloc];
}


推荐答案

[super dealloc] 被调用。一旦调用 [super dealloc] ,你就不能再依赖 NSObject (或者你的根类是什么)机械功能正常。之后,你的超类' -dealloc 方法应该调用其超类'等,直到根类 -dealloc 方法被调用。在这一点上,这些类分配完成他们的工作的一切都可能会消失,如果你尝试使用它们,你就处于未定义的领域。

Yes, it absolutely maters when [super dealloc] is called. Once [super dealloc] is called, you can no longer rely on the NSObject (or whatever your root class is) machinery to function properly. Afterall, your super-class' -dealloc method should call its superclass' etc. until the root class' -dealloc method is called. At that point, everything that these classes allocate to do their job is potentially gone and you're in undefined territory if you try to use any of it.

您的 -dealloc 方法应该总是看起来像

Your -dealloc method should always look like

- (void)dealloc
{
   // release my own stuff first

   [super dealloc];
}

这篇关于当在dealloc中调用super是否重要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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