Where do we put code that was in -dealloc when converting to ARC?

automatic-ref-counting, ios, iphone, objective-c

Solution

The `dealloc` stays in ARC, it's just that you shouldn't be calling `[super dealloc]` any longer: the compiler inserts the code for you. And of course all the calls to `release` cannot be made in `dealloc` (or anywhere else).

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

Problem

I have a class with this method call within dealloc: ``` - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; [super dealloc]; } ``` Where would I remove myself from the notification center once I convert the class to ARC? Should it go within viewDidUnload? The notification is used to listen for events that come from a modal view controller, so I cannot put this code into viewWillDisappear.

Original source