I thought this would crash, but it doesn't seem to
I have a UIViewController subclass with the following:
- (void)viewDidLoad {
[super viewDidLoad];
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
[nc addObserver: self
selector: @selector(userDataChanged:)
name: kUserDataUpdated
object: nil];
}
- (void) dealloc {
NSLog(@"hello");
}
- (void) userDataChanged: (NSNotification *)notif {
[self configureWithLoggedInUser];
}
a breakpoint in viewDidLoad suggests addObserver is getting called as expected
a breakpoint in userDataChanged suggests i'm able to trigger my notification.
a breakpoint in dealloc suggests dismissing the view/controller is working as expected.
But I thought the next time the app posted kUserDataUpdated the app would crash.
currently when I:
1. load my viewController
2. dismiss/deallocate it
3. post kUserDataUpdated
nothing bad is happening.
Is it no longer necessary to call removeObserver in dealloc?
or am I avoiding a crash because this is running in the simulator (lots of mem) and I haven't done much else between steps 2 and 3?
thanks,
Mike