What's the best practice for adding and removing observers to/from NSNotificationCenter
?
I'm wondering if adding self
as an observer in viewDidLoad
and removing self
in viewDidUnload
is sufficient. Or perhaps I should remove self
in dealloc
as well.
Perhaps low memory conditions need to be considered. I could see adding in viewDidLoad
and removing in dealloc
being problematic: viewDidUnload
is called due to low memory... then viewDidLoad
is called when the view is displayed again... now self
has been added as an observer twice w/o being removed (since dealloc
wasn't called).
Note: I'm considering just a basic example where self
refers to a UIViewController
subclass.