Re: Crash in KVO when using -keyPathsForValuesAffecting<Key>
Re: Crash in KVO when using -keyPathsForValuesAffecting<Key>
- Subject: Re: Crash in KVO when using -keyPathsForValuesAffecting<Key>
- From: Jean-Daniel Dupas <email@hidden>
- Date: Sun, 21 Jun 2009 14:12:54 +0200
Le 21 juin 09 à 11:26, Quincey Morris a écrit :
On Jun 20, 2009, at 14:15, Jean-Daniel Dupas wrote:
Thank you for the suggestion, but it does not solve the problem.
Even trying w1.object = nil before unregistring the observer has no
effect.
When I looked at your code a little harder, I realized my theory
could not have been correct anyway. For a start, the MyObject was
being leaked, so its dealloc would never be called.
On Jun 20, 2009, at 11:08, Jean-Daniel Dupas wrote:
[w1 removeObserver:foo forKeyPath:@"name"];
[w1 release];
Interestingly, changing this to:
[w2 removeObserver:foo forKeyPath:@"name"];
[w2 release];
works just fine, thought it ought to have exactly the same behavior
as the original version. So here's a new theory ...
The observations you set up manually *both* cause a secondary/
indirect observation, where 'foo' observes (in effect if not
actually) the "name" property of the *same* MyObject. In effect, you
have the same observer object observing the same property of the
same target object twice. (That's something you can't do directly,
AFAIK.)
When a secondary/indirect observation needs to be removed (either
because a manual observation is removed, or -- as we discovered when
you tried 'w1.object = nil' -- for a different reason) it looks like
the wrong one can get removed. Or something like that.
Gratz. That's a very elegant bug. :)
Thank you for your time.
That's my conclusion too. I filled a report, and I'm trying to
workaround this bug by observing the "subproperty" myself instead of
using automatic dependency tracking.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden