Do I need use dealloc method with ARC?

后端 未结 5 1710
别跟我提以往
别跟我提以往 2021-02-01 14:03

So, I have class:

@interface Controller : NSObject
{
    UILabel* fileDescription;
}

@property(strong, nonatomic) UILabel* fileDescription;

D

相关标签:
5条回答
  • 2021-02-01 14:40

    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.

    0 讨论(0)
  • 2021-02-01 14:46

    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.

    0 讨论(0)
  • 2021-02-01 14:47

    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.

    0 讨论(0)
  • 2021-02-01 14:57

    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.

    0 讨论(0)
  • 2021-02-01 14:57

    Ans is NO Because with ARC no need to dealloc.

    0 讨论(0)
提交回复
热议问题