[英]Do I need use dealloc method with ARC?
So, I have class: 所以,我上课了:
@interface Controller : NSObject
{
UILabel* fileDescription;
}
@property(strong, nonatomic) UILabel* fileDescription;
Do I need use method dealloc where property fileDescription will equal nil? 我是否需要使用方法dealloc,其中属性fileDescription将等于nil?
For example: 例如:
-(void)dealloc
{
fileDescription = nil;
}
If not, who will dismiss memory used by fileDescription? 如果没有,谁将解雇fileDescription使用的内存?
Generally you don't need to provide a subclassed dealloc
method as ARC manages the lifetime of the instance variables. 通常,您不需要提供子类
dealloc
方法,因为ARC管理实例变量的生命周期。
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. 因此,您可以在ARC下
dealloc
,但不允许您在子类方法中调用[super dealloc]
。
In your particular case it's not required, however. 但是,在您的特定情况下,它不是必需的。
No. 没有。
You don't need dealloc
method in ARC
. 你不需要
ARC
dealloc
方法。
But if you want to do some cleanup tasks when your view is dismissing or released. 但是,如果您想在视图被解雇或释放时执行一些清理任务。 It's the best place, In such case you can implement it.
这是最好的地方,在这种情况下你可以实现它。
For example: 例如:
You are running a timer in your view and it's updating your view. 您正在视图中运行计时器,它正在更新您的视图。 When you are dismissed the view you need to stop that timer.
当您解除视图时,您需要停止该计时器。 In that condition you can use dealloc method and stop timer there.
在那种情况下你可以使用dealloc方法并在那里停止计时器。
Similar for NSNotification
observer. 类似于
NSNotification
观察员。
If you are using ARC. 如果您使用ARC。
No need to use dealloc and release, compiler knows that your property and objects are strong / weak so it will manage it. 不需要使用dealloc和release,编译器知道你的属性和对象是强/弱的,所以它会管理它。
EDIT: 编辑:
dealloc
method is required if you use coreframework objects like CG...
& CF...
. 如果你使用像
CG...
& CF...
这样的coreframework对象,则需要dealloc
方法。 Even you create observers for notifications you need to remove it and dealloc
is the best place to removeObserver. 即使您为需要删除它的通知创建观察者,
dealloc
也是removeObserver的最佳位置。
Ans是NO因为ARC不需要dealloc。
As you are using ARC you don't have to use dealloc
Complier will set the autoreleasePool depending upon the scope of the property,variable or control. 当您使用ARC时,您不必使用
dealloc
Complier将根据属性,变量或控件的范围设置autoreleasePool。 And it'll will release
the memory. 它会
release
内存。 There are different types of autoreleasepool generally we can define them as function level,class level etc etc. Hope this helps. 有不同类型的autoreleasepool我们通常可以将它们定义为功能级别,类级别等等。希望这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.