简体   繁体   中英

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

-(void)dealloc
{
    fileDescription = nil;
}

If not, who will dismiss memory used by fileDescription?

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.

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.

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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM