Hi Corbin,

>> I have a NSButton in C to remove from the array controller the A object it 
>> represents. However, each time I click on that button, I first get a warning 
>> telling me that I remove an observed object before releasing the observer, 
>> and then the program crash,
> 
> If you have a crash, it is always best to post the crash report.

Well, I wrote a workaround, so I can't give you a crash report anymore.
The crash happens in the KVO unregistering routine.

The problem is that when the represented object is removed from the array 
controller, the corresponding NSView is not immediately released. Instead, 
there is an implied CAAnimation (or something similar) that makes the NSView 
slowly fade away. Net result is that the NSView survives some tenths of a 
second after the represented object is released, and the KVO unregistering 
crashes.

The (very dirty) workaround is this: instead of immediately release the 
represented object, retain it, target it for delayed deletion, and then remove 
it from the array; the real deletion is triggered in the dealloc routine of the 
corresponding NSView (or subclass thereof) :

// Highly heterodox
- (void)dealloc {
        [super dealloc];
        [[[[NSApp delegate] appController] layerManager] removeTargetedCALayer];
}

I had to write it this way, instead of the more orthodox :

- (void)dealloc {
        [[[[NSApp delegate] appController] layerManager] removeTargetedCALayer];
        [super dealloc];
}

because the KVO removal takes place in the [super dealloc] routineā€¦

Great WE,
Vincent_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to