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消失,爲什麼沒有存儲的觀察信息消失?