Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is removeObserver necessary on dealloc?

In one of my view controller, it adds itself as observer of UITextViewTextDidEndEditingNotification notification, like the following does

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(done:) name:UITextViewTextDidEndEditingNotification object:nil];

Now I am wondering - do I need to do the following when the view controller is dealloc'd

[[NSNotificationCenter defaultCenter] removeObserver:self];
like image 207
tom Avatar asked May 30 '26 18:05

tom


1 Answers

yes, you should always remove any observers when they're being dealloc'd. otherwise the notification center will keep references to the now-dealloc'd objects around and continue to try to forward notifications to them.

like image 115
Mike K Avatar answered Jun 01 '26 08:06

Mike K



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!