问题描述
上帝已经改变了许多习惯进入我孤立的丛林村庄,例如:
The gods have parachuted many habits into my isolated jungle village, such as:
- (void) dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
他们的方式对我很奇怪,理解他们。
Their ways are strange to me, yet I still seek to understand them.
为什么要清理松散的东西,如果实例离开呢?该实例的引用/保留计数不会递减?它会隐藏某种类型的通知哈希表,其中包含所有监听器的列表。
Why bother cleaning loose ends up if the instance is going away? Will the reference/retain count to that instance not be decremented? Will it clutter some sort of Notification Hash Table lurking out there that holds a list of all the listeners?
推荐答案
NSNotificationCenter
不保留观察器。如果你不删除观察者,并且观察者被释放,那么 NSNotificationCenter
就会留下一个悬空指针,当它下一次尝试通知观察员。
NSNotificationCenter
doesn't retain observers. If you don't remove the observer, and the observer is deallocated, then NSNotificationCenter
is left holding a dangling pointer which will (most often) crash when it next tries to notify the observer.
这篇关于NSNotificationCenter:为什么要调用removeObserver?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!