In an iOS 6 app I have some view controllers that are added as observers with the default notification center. They are added in the viewDidLoad
method because I want the controllers to receive the notifications even when they are not on top.
A lot of people recommend removing the observer in the dealloc
method. However, I have been logging messages with NSLog()
both when adding and removing the observer, and it looks like dealloc
is never called (I am using ARC).
Contrary to what one would think, the viewDidUnload
method is not an option, since in iOS 5 it was only called during low-memory conditions, and in iOS 6 it is not called at all.
It actually seems that there is no way to do what the documentation requires! So far, my application has not crashed, by the way, even though controllers are being added multiple times and (apparently) never removed.
Note: So far I have been testing with the simulator only; is it possible that dealloc
does get called in an actual device, but not in the simulator? Or is the call to NSLog()
just not showing up (it shows up everywhere else, though).