Warning about deallocation of document object with registered key value observers
Warning about deallocation of document object with registered key value observers
- Subject: Warning about deallocation of document object with registered key value observers
- From: Rick Hoge <email@hidden>
- Date: Thu, 8 Apr 2004 14:26:17 -0400
I recently encountered the following warning in a document-based when I
quit the program or close a document:
An instance 0x38e3c0 of class MyDocument is being deallocated while key
value observers are still registered with it. Break on
_NSKVODeallocateLog to start debugging.
The cause is that I register an NSView as an observer of the document
in the view's awakeFromNib method. Up until now, all my views have
been observers for NSWindowController subclasses and I have never had
this error. It only seems to happen when observers are registered for
the document.
Is it really necessary to remove these observers on document close? I
suppose I could either remove all the observers in the document's
dealloc method or have the view remove any observers it registered on
close time. I'm having a hard time finding a clean method for either
solution. I thought I could get the list of observers from within the
document's dealloc using observationInfo, but this returns an array of
objects with type NSKeyValueObservance that seems undocumented. I also
can't think of any standard message that would be sent to the view when
the window is closed. I guess I could register to watch for the window
closing notification, but it seems to be a lot of extra code lines just
to get rid of this warning... the difficulty in getting rid of the
warning makes me wonder if it's indicative of some design flaw relating
to registering an observer for a document.
Rick
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.