Do I need use dealloc method with ARC?

偶尔善良 提交于 2019-12-20 09:27:50

问题


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?
For example:

-(void)dealloc
{
    fileDescription = nil;
}

If not, who will dismiss memory used by fileDescription?


回答1:


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

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.




回答2:


No.

You don't need dealloc method in ARC.

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.

Similar for NSNotification observer.




回答3:


If you are using ARC.

No need to use dealloc and release, compiler knows that your property and objects are strong / weak so it will manage it.

EDIT:

dealloc method is required if you use coreframework objects like CG... & CF.... Even you create observers for notifications you need to remove it and dealloc is the best place to removeObserver.




回答4:


Ans is NO Because with ARC no need to dealloc.




回答5:


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. And it'll will release the memory. There are different types of autoreleasepool generally we can define them as function level,class level etc etc. Hope this helps.



来源:https://stackoverflow.com/questions/14501115/do-i-need-use-dealloc-method-with-arc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!