Re: Best place to remove observer for NSViewBoundsDidChangeNotification
Re: Best place to remove observer for NSViewBoundsDidChangeNotification
- Subject: Re: Best place to remove observer for NSViewBoundsDidChangeNotification
- From: Jerry Krinock <email@hidden>
- Date: Mon, 25 Feb 2008 15:15:06 -0800
On 2008 Feb, 25, at 14:15, Jonathan Dann wrote:
On dealloc, the document calls [[NSNotificationCenter defaultCenter]
removeObserver:self], but these notifications still get sent to the
dealloc'd instance when the window itself closes. I think this is
something to do with the notification being sent/received in a
delayed manner, am I right?
I don't know. Verify this by putting an NSLog("deallocc done") as the
last statement in dealloc and see if it crashes before then. (You
didn't say so, but, from experience, I presume that sending a
notification to a deallocced object causes a crash?)
I've now overridden NSDocument's -close method to remove self from
observing these notifications before calling [super close] (which
works fine) but I was wondering if there was a better, more
conventional place to put these -removeObserver: calls. I'm not
sure if this makes sense but are there any view-related methods that
get called when a document/window closes that would be the best
place to de-register for observations of view notifications? Could
what I've done bite me if, for example, for some reason -close does
not get called?
Oh, yes, it will bite you. Says so right in the documentation of -
[NSDocument close].
When I had a problem like this one time I ended my -dealloc like this:
[super dealloc] ;
self = nil ;
}
Unfortunately, I didn't write any comments as to whether that self=nil
actually fixed the problem or was just "extra insurance". But I'm
sure my idea was that sending a notification to nil would be harmless,
like sending a message to nil.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden