On 30/08/2009, at 7:46 PM, Andreas Grosam wrote:

This is not exactly what I got in the console. Actually it is:
"An instance 0xd21b60 of class MyObservee is being deallocated while key value observers are still registered with it. "

Notice:  "is being deallocated"

This is also **exactly** what happens in my code: the dealloc method has been sent to the observed object and - at this point - KVOs are still registered.


What I can't quite follow Andreas, is that *you* must be sending the - release message to the object, which in turn is calling dealloc. So why not just stop observing before you call release? That's what you're supposed to do. Call me dense (feel free!) but if you are unable to do that because of the design of your code, the code design needs to be fixed. Simple as.

I believe all the discussion about the logging of error messages is a red herring. If your code is broken, it's broken. Arguing about exactly which version words the message which way isn't helping you fix it. If the problem is that you are not retaining to avoid a retain cycle, and therefore are not in control of the release such that you can't stop observing just prior, that to me indicates a broken design. That's what you need to be sorting out.

As I understand it you have a situation where nodes of a tree are observing other nodes (sibling or otherwise) in the same tree, but at the same time these nodes are owned by their parent nodes, so cannot retain the other nodes that they are observing. Forgive my bluntness, but it sounds like a bad data structure design that was the product of one too many tequilas late on a Friday night! If a node even needs to observe another node in order to fulfil its function, maybe a tree structure isn't even the right design at all? Your solution of having some sort of shutdown message blowing all over your leaves is a band- aid on a gaping wound. Instead, why not strictly forbid nodes from observing other nodes, and instead move messages only along the branches. If a node needs to know what another node has done, it can do so because the single common node (or root) between the two passes that message. It means that the only KVO observers of a node allowed are its parent nodes (or root), which already owns it so it can simply stop observing when the child node is released.

--Graham


_______________________________________________

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