简体   繁体   English

我需要在ARC中使用dealloc方法吗?

[英]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? 如果没有,谁将解雇f​​ileDescription使用的内存?

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.

相关问题 我们是否需要在Obj-C ARC模式下的dealloc方法中手动释放块变量? - Do we need to release block variable manually in dealloc method under Obj-C ARC mode? 我需要在dealloc中释放吗? - Do I need release in the dealloc? 我创建了一个没有ARC的新项目,但是没有dealloc方法 - I created a new project w/o ARC, but there's not dealloc method 我需要在dealloc方法中将release发送到我的实例变量吗? (iOS) - Do I need to send release to my instance variable in the dealloc method? (iOS) 对于 Xcode 生成的 Core Data 托管对象,我是否需要添加一个 dealloc 方法来释放变量? - for Xcode produced Core Data managed objects, do I need to add a dealloc method to release variables? UIViewController不会在ARC项目中调用dealloc吗? - UIViewController do not call dealloc in ARC project? iPhone内存管理:我需要在dealloc中释放什么? - IPhone Memory Management: What do I need to release inside dealloc? 我需要在xcode4.2中还原dealloc吗? - Do I need to restore dealloc in xcode4.2? 当我使用“layoutSubviews”或“didMoveToSuperview”时不要调用“dealloc”方法 - Don't call “dealloc” method when I use “layoutSubviews” or “didMoveToSuperview” 在转换为ARC时,我们将-dealloc中的代码放在哪里? - Where do we put code that was in -dealloc when converting to ARC?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM