目标C:对象已释放,而键值观察者仍在其中注册

Zhe*_*hen 17 core-data objective-c key-value-observing ios

在向核心数据模型添加2个附加字段后,我遇到了以下错误.

CarPark_CarPark_ 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:
<NSKeyValueObservationInfo 0x1b6510> (
<NSKeyValueObservance 0x19b210: Observer: 0x1a8cf0, Key path: coordinate, 
Options: <New: NO, Old:     NO, Prior: YES> Context: 0x0, Property: 0x1b7e00>
)
Run Code Online (Sandbox Code Playgroud)

我对下一步做什么有点迷茫.任何有关这方面的指导将非常感谢!请让我知道还需要哪些其他信息.

Mar*_*ger 28

要设置断点,请打开Xcode 4(Xcode 3中的Breakpoints窗口)中的断点选项卡,并为符号"NSKVODeallocateBreak"添加新的符号断点

使用调试器控制台在观察信息中给出的地址处打印观察者

观察者:0x19af20

po 0x19af20
Run Code Online (Sandbox Code Playgroud)

这应该提供有关观察者的一些有价值的信息.在您的自定义CarPark类中覆盖addObserver:forKeyPath:options:context:并设置断点以查看正在建立的观察的确切位置.


小智 9

这可能是由于观察者在观察物体之前被解除分配.您需要实现- (void)dealloc方法来删除观察者中的所有观察对象.