I'm seeing this warning printed in an app that's linked and run on Leopard. Any ideas? Colin, Mike: how did you deal with it?

I have an object observing itself (through bindings) and it removes itself as an observer inside its -dealloc method:

    - (void)dealloc
    {
        [self unbind:@"fbItem"];
        [self unbind:@"cost"];
        ...
        [super dealloc];
    }

At runtime, the NSKVODeallocateBreak warning is printed to the console (both stderr and through syslog, so it clutters up the user's log database):

An instance 0xcdcc30 of class MenuStructureNode is being deallocated while key value observers are still registered with it. Observation info is being leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info:
<NSKeyValueObservationInfo 0x154bb9f0> (
<NSKeyValueObservance 0x1709cfb0: Observer: 0x154f66a0, Key path: menuFbItem.fbItem, Options: <New: NO, Old: NO, Prior: NO> Context: 0x0, Property: 0x15320bb0> <NSKeyValueObservance 0x154cc0d0: Observer: 0x154f66a0, Key path: menuFbItem.cost, Options: <New: NO, Old: NO, Prior: NO> Context: 0x0, Property: 0x154c0eb0>

If I move the observation-removal code to -release, so it's called before -dealloc, the warning goes away:

    - (void)release
    {
        if ([self retainCount] == 1) {
            [self unbind:@"fbItem"];
            [self unbind:@"cost"];
        }
        [super release];
    }

Any idea how to suppress the "NSKVODeallocateBreak" warning? I really don't like overriding -release. This object is a model object (not a view), so there's not really a good place to clean up other than - dealloc.

The current behavior seems incorrect -- the warning shouldn't be printed until the object is truly deallocated (NSObject's -dealloc method), to allow for cleanup to occur in subclasses' -dealloc methods. Does anyone have a Radar ID I should reference to file a new bug?

On May 11, 2008, at 6:09 PM, Mike Abdullah wrote:

This is a general problem with KVO when observing self. As I understand, Apple has recognised the issue though and for apps linked or run on Leopard (one of the 2) the system should be intelligent enough to not print warnings. The best alternative I can suggest is to override -release so that you can sneak some kind of - willDealloc method in before the actual de-allocation and subsequent warnings.

Mike.

On 11 May 2008, at 22:53, Colin Cornaby wrote:

But see, that's the thing. My objects dealloc method fires AFTER the warning appears, so my object hasn't actually been deallocated yet.

In the deallocation my object removes the observers from itself. If my object was actually deallocating first, I should be getting this message.

I'll do some poking around, but I don't think this is a memory management issue. Wouldn't be the first time I've had to eat my words though. :p

On May 11, 2008, at 2:47 PM, Kyle Sluder wrote:

On Sun, May 11, 2008 at 5:19 PM, Colin Cornaby <[email protected] > wrote:
#0      0x94eb4993 in NSKVODeallocateBreak
#1      0x94e267c4 in NSKVODeallocate
#2      0x94d7d57f in NSPopAutoreleasePool
#3      0x945b1e54 in -[NSApplication run]
#4      0x9457f030 in NSApplicationMain
#5      0x00008208 in main at main.m:13

See stack frame #2?  You should immediately have recognized that you
have a memory management issue on your hands.  You're failing to
retain the object somewhere.

--Kyle Sluder

_______________________________________________

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/cocoadev%40mikeabdullah.net

This email sent to [email protected]

_______________________________________________

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/chris_campbell%40mac.com

This email sent to [email protected]

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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