释放和解除分配消息的顺序 [英] Order of release and dealloc messages

查看:30
本文介绍了释放和解除分配消息的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

推荐的做法是什么?我应该首先调用super dealloc还是最后调用,这无关紧要吗?

What is the recommended way of doing this. Should I call super dealloc first or last or doesn't it matter?

- (void)dealloc
{
    [super dealloc];
    [orderNumber release];
    [orderDate release];
}

还涉及诸如didViewLoad之类的覆盖方法-我应该首先调用super吗?

Also when it comes to overriding methods like didViewLoad - should I call super first or last?

推荐答案

始终致电 [super dealloc] last ,否则您可能会因为工作而容易遇到麻烦在陈旧的对象上.

Always call [super dealloc] last or you might easily come into trouble because you're working on a stale object.

使用didViewLoad,您通常可以在自己的代码之前调用它,因为您希望在此之前执行标准初始化工作.不过,我已经在Apple的代码中看到了一些根本没有调用超级实现的示例,因此也许没有太多事情要做.

With didViewLoad you normally call it before your own code as you want the standard initialization stuff executed before. I've seen examples in Apple's code that don't call the super implementation at all, though, so maybe there's not much going on anyway.

这篇关于释放和解除分配消息的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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