On Sun, Sep 30, 2012, at 10:57 AM, Lee Ann Rucker wrote: > Weird that you didn't get the warning, but we've switched to the pattern > of > > [self addObserver:self forKeyPath:@"ctrl.selectedObjects.someString"... > > and that's saved countless headaches. You can remove your own observers > in dealloc so you never need to worry about when to remove the observer.
Self-observation has always been a code smell to me. I suppose it's a lot better now that we have -removeObserver:forKeyPath:context:. In general, it is not a good idea to rely on -dealloc for cleanup of anything other than object references (that is, sending -release to strong ivars). Any other resource that requires explicit management (NSNotificationCenter registration, KVO, file handles, etc.) should not be managed in -dealloc unless that resource is *explicitly* tied to the lifetime of the object (a reuse pool, logging). I'd add and remove my observation in -setCtrl:. Or, since this is a view controller, perhaps add an explicit teardown method (-removeViewFromWindow or -windowIsClosing or something) and remove my observation there. --Kyle Sluder _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com