is removeObserver necessary on dealloc?

核能气质少年 提交于 2019-12-06 07:23:53

问题


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];

回答1:


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.



来源:https://stackoverflow.com/questions/8665575/is-removeobserver-necessary-on-dealloc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!