在转换为ARC时,我们将-dealloc中的代码放在哪里?

Ale*_*one 11 iphone objective-c ios automatic-ref-counting

我在dealloc中有一个带有此方法调用的类:

- (void)dealloc {

    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super dealloc];
}
Run Code Online (Sandbox Code Playgroud)

将类转换为ARC后,我将自己从通知中心移除?它应该在viewDidUnload中吗?该通知用于侦听来自模态视图控制器的事件,因此我无法将此代码放入viewWillDisappear中.

das*_*ght 19

dealloc在ARC停留,它只是你不应该调用[super dealloc]任何更长:编译器插入代码为您服务.当然,所有的呼叫release都不能在dealloc(或其他任何地方)进行.

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    // [super dealloc]; <<== Compiler inserts this for you
}
Run Code Online (Sandbox Code Playgroud)