Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 434
Zhen Avatar asked May 12 '11 18:05

Zhen


2 Answers

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.

like image 92
Martin Brugger Avatar answered Sep 18 '22 20:09

Martin Brugger


It's probably due to the observer being deallocated before the objects being observed. You would need to implement the -(void) dealloc method to remove all observed objects in the observer.

like image 20
maarut Avatar answered Sep 16 '22 20:09

maarut