-
-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix an event handler leak in Binding.RemovePropertyEvent
#2644
Fix an event handler leak in Binding.RemovePropertyEvent
#2644
Conversation
Removing the handler in `RemovePropertyEvent` doesn't work, as the `Target` of the handler is not the `PropertyNotifyHelper` instance; it is the object that the handler is bound to. Instead, find the correct handler to remove by checking all invocations of the `PropertyChanged` event of the bound object, and comparing the internal handler of the invocation with the method's argument. Also, add unit tests to verify the correct behavior.
Hey @joerih, thanks for submitting the fix and especially for the unit tests. |
@cwensley Hi Curtis. Is there any chance this fix can be included in the upcoming release? |
Hey @joerih, sorry for the late response. There are a few problems I noticed with this, namely the existing API is actually not complete enough to do this properly, as calling RemovePropertyEvent for the same method (but different properties) would remove it for all properties, not just the one you specify (even though your implementation only removes the first one). This may mean an API break to return a value for I've done some changes locally for this and it seems to work. I'll try to push some changes for you to review shortly. |
…to the same delegate.
21e9f25
to
f9b4a85
Compare
Ok I've added some changes. Please take a look to see if I've missed anything. In particular, the
The return value for E.g. one would do something like this:
This is also totally valid:
The previous behaviour that you fixed up would still work:
However it was ambiguous in this scenario:
|
@cwensley Hi Curtis. Thanks for your response and for improving the fix. Indeed, I struggled to get this working without changing the API - something I didn't want to do because I was not sure about the consequences. But this way it is even better, as far as I can tell it should cover all scenarios. |
Yeah, I am hesitant to make ABI breaking changes as well. I am thinking instead to obsolete the |
Yes, that would also work well I think. At the moment we implemented a workaround to avoid the memory leak in our application, and it would not be a problem to switch to a new API when we remove this workaround in the future. |
- return for AddPropertyEvent is now void like before to avoid ABI breaks - Use PropertyBinding to wire up property events in DelegateBinding so it supports both INotifyPropertyChanged and MyPropertyChanged events
43a1912
to
e79a63b
Compare
Removing the handler in
RemovePropertyEvent
doesn't work, as theTarget
of the handler is not thePropertyNotifyHelper
instance; it is the object that the handler is bound to.Instead, find the correct handler to remove by checking all invocations of the
PropertyChanged
event of the bound object, and comparing the internal handler of the invocation with the method's argument.Also, add unit tests to verify the correct behavior.
fixes #2446