3
我有一个班级,我正在使用它作为自己的观察员。我需要它在其他对象改变其属性时通知我。当它被释放时,我不费心去除观察者。不过,我得到这样的错误:观察信息泄露
An instance 0xf819680 of class **** was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info:
现在,我真的不明白为什么这将是一个问题。我的志愿的理解是,如果对象A想要观察对象B,则A保留B,然后
[B addObserver:A]; // shortened just to get the point across
和B确实不保留,以避免循环。因此,如果A得到处理,它必须将其本身作为B的观察者移除,否则B将不具有对A曾经在哪里的引用(因为它确实保留了A)不是。
但是,这个警告似乎意味着如果我释放B坏东西会发生。我能想象的唯一事情就是B对B的弱引用将会消失,A将不会再收到任何通知。我不知道“观察信息被泄露”。如果B消失,为什么没有存储的观察信息消失?