3

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];
tom
  • 14,273
  • 19
  • 65
  • 124
  • Docs: "If your app targets iOS 9.0 and later or macOS 10.11 and later, you don't need to unregister an observer in its deallocation method. If your app targets earlier releases, be sure to invoke removeObserver:name:object: before observer or any object specified in addObserver:selector:name:object: is deallocated." – Liviu Jul 31 '17 at 16:15

1 Answers1

4

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.

Mike K
  • 2,227
  • 1
  • 12
  • 6