![](/img/trans.png)
[英]Do we need to release block variable manually in dealloc method under Obj-C ARC mode?
[英]Where do we put code that was in -dealloc when converting to ARC?
我在dealloc中有一个带有此方法调用的类:
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
将类转换为ARC后,我将自己从通知中心移除? 它应该在viewDidUnload中吗? 该通知用于侦听来自模态视图控制器的事件,因此我无法将此代码放入viewWillDisappear中。
dealloc
保留在ARC中,只是你不应该再调用[super dealloc]
:编译器会为你插入代码。 当然,所有release
的调用都不能在dealloc
(或其他任何地方)中进行。
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
// [super dealloc]; <<== Compiler inserts this for you
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.