Le 29 août 2009 à 14:08, Andreas Grosam a écrit :


On Aug 29, 2009, at 2:29 AM, Graham Cox wrote:


Thank you Graham for your reply.

Hi Andreas,

There is a strong code smell here.

How does your observee know who its observers are?
Actually, it does not. My example code is an oversimplification to show the actual issue. Often, things are much more complex, and explainig them may draw people away from the actual problem. ;)

The *Observer*  will do this:

- (void) dealloc {
  [self.observee removeObserver:self forKeyPath:key];
}


However, in my code the *Observee* will receive the dealloc method first, which in turn causes all its "child" objects - the Observers - to receive its dealloc message - which is shown above. Here, the observee is the "parent" object that owns the child objects.


So, the call path is about this:

[observee release]
        [observee dealloc]
                [observer release]
                        [observer dealloc]
                                [obse
rvee removeObserver:observer forKeyPath:key]


Did you try on Snow Leopard.

http://developer.apple.com/mac/library/releasenotes/Cocoa/Foundation.html
Bug Fixes in Debugging of Objects Being Deallocated With Observers Still Registered When Not Running Garbage-Collected (Updated since March 2009 Seed)
[…]
There was another bug in which this logging was done spuriously when an object observed by a second object was deallocated, its deallocation caused the release of the second object, and the second object correctly unregistered itself as an observer of the first object at that time due to its own deallocation. This bug has also has been fixed in Mac OS 10.6.



_______________________________________________

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