Skip navigation.
 
mlRe: Best place to remove observer for NSViewBoundsDidChangeNotification
FROM : Jonathan Dann
DATE : Tue Mar 04 19:29:48 2008

On 25 Feb 2008, at 23:30, Jonathan Dann wrote:

>
> On 25 Feb 2008, at 23:15, Jerry Krinock wrote:
>

>> I presume that sending a notification to a deallocced object causes 
>> a crash?

>
> Invariably! ;)
>

>> Oh, yes, it will bite you.  Says so right in the documentation of -
>> [NSDocument close].

>
> Funny how I read that so many times last week when overriding -
> canCloseDocument: but then forget immediately.
>

>> When I had a problem like this one time I ended my -dealloc like 
>> this:
>>
>>  [super dealloc] ;
>>  self = nil ;
>> }

>
> I'll try it, just looking for a 'clean' implementation, so I 
> unregister at the right point.


Just for completeness,

I found that I was registering for the notifications of a view in my 
NSDocument's -init method, not in the -windowDidLoadNib.  Therefore 
the object: argument of -addObserver:selector:name:object: was nil, 
thus I was getting *all* notifications.  Moving the registration to -
windowDidLoadNib: sorted it all as the object I wanted to watch was 
instantiated.

Jon

Related mailsAuthorDate
mlBest place to remove observer for NSViewBoundsDidChangeNotification Jonathan Dann Feb 25, 23:15
mlRe: Best place to remove observer for NSViewBoundsDidChangeNotification Jerry Krinock Feb 26, 00:15
mlRe: Best place to remove observer for NSViewBoundsDidChangeNotification Jonathan Dann Feb 26, 00:30
mlRe: Best place to remove observer for NSViewBoundsDidChangeNotification Jonathan Dann Mar 4, 19:29