Objective C:Object Deallocated while key value observers were still registered with it

Zhen picture Zhen · May 12, 2011 · Viewed 17.9k times · Source

I am hitting the below error after I added 2 additional fields to my core data model.

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>
)

I am a little lost on what to do next. Any guidance on this will be greatly greatly appreciated! Please let me know what other information is required.

Answer

Martin Brugger picture Martin Brugger · May 13, 2011

To set the breakpoint open the breakpoints tab in Xcode 4 (Breakpoints window in Xcode 3) and add a new symbolic Breakpoint for the symbol "NSKVODeallocateBreak"

Use the debugger console to print the observer at the adress given in the observation info

Observer: 0x19af20

po 0x19af20

This should give some valuable information about the observer. Override addObserver:forKeyPath:options:context: in your custom CarPark class and set a breakpoint to see the exact location of the observing being established.