我需要在ARC中使用dealloc方法吗? [英] Do I need use dealloc method with ARC?

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

问题描述

所以,我有课:

@interface Controller : NSObject
{
    UILabel* fileDescription;
}

@property(strong, nonatomic) UILabel* fileDescription;

我是否需要使用方法dealloc,其中属性fileDescription将等于nil?

For例如:

Do I need use method dealloc where property fileDescription will equal nil?
For example:

-(void)dealloc
{
    fileDescription = nil;
}

如果没有,谁将解除fileDescription使用的内存?

If not, who will dismiss memory used by fileDescription?

推荐答案

通常,您不需要提供子类 dealloc 方法,因为ARC管理生命周期实例变量。

Generally you don't need to provide a subclassed dealloc method as ARC manages the lifetime of the instance variables.

然而,除了释放对象之外,执行清理会很有用,例如删除观察者或关闭网络连接干净利落。因此,您可以在ARC下继承 dealloc ,但不允许您从中调用 [super dealloc] 子类方法。

However it can be useful to perform clean-up other than releasing objects, for example to remove an observer or close a network connection down cleanly. You are therefore allowed to subclass dealloc under ARC, but you are not allowed to call [super dealloc] from within the subclassed method.

然而,在您的特定情况下,它不是必需的。

In your particular case it's not required, however.

这篇关于我需要在ARC中使用dealloc方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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