0

我一直有这个错误的麻烦:

“Actor 类的实例 0x156ad8d0 已被释放,而键值观察者仍向其注册。观察信息已泄露,甚至可能被错误地附加到其他对象。在 NSKVODeallocateBreak 上设置断点以在调试器中停止。这是当前观察信息:”

有没有一种有效的方法来注销接收者正在观察的所有对象,以及注销所有正在观察它的对象?我能找到取消注册的唯一方法是通过 removeObserverForKeyPath - 这需要我跟踪所有已注册的对象和键路径,这可能会变得很麻烦。

4

1 回答 1

1

Use removeObserverForKeyPath: as @Kevin suggested.

However, you really should be removing the observers prior to deallocation. During deallocation, the state of the instance will be inconsistent, most likely. Especially when dealing with a class hierarchy. Thus, having observers active during deallocation is often the source of some really wonky, hard to fix, bugs.

于 2013-10-05T17:45:42.700 回答