On 2009 Aug 29, at 23:59, Michel Schinz wrote:

I'm therefore looking for better solutions, and would be interested to know what people have come up with.

I believe the best answer to the question of "when to stop observing" is "as soon as possible".

I was having trouble with a Core Data document (NSPersistentDocument) observing too long, until I started cleaning things like this up in - [NSDocumentController removeDocument:]. See typical code below.

You should also scroll down in your mailbox and read the thread which was still active yesterday, "Re: Get error message about registered observers when Object receives dealloc message". There is a good discussion of this issue.

In the implementation of my subclassed NSDocumentController....

- (void)removeDocument:(NSDocument *)document {
    // Remove observations by document's window controller
[[MAKVONotificationCenter defaultCenter] removeObserver: [(Bkmslf*)document bkmslfWinCon]] ; [[NSNotificationCenter defaultCenter] removeObserver: [(Bkmslf*)document bkmslfWinCon]] ;

    // Remove observations by document itself
    [[NSNotificationCenter defaultCenter] removeObserver:document] ;
    [[MAKVONotificationCenter defaultCenter] removeObserver:document] ;

[SSYMOCManager removeManagedObjectContext:[(Bkmslf*)document managedObjectContext]] ;

    [super removeDocument:document] ;
}


_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to