Skip to content
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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

joerih
Copy link

@joerih joerih commented Apr 16, 2024

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.

fixes #2446

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.
@cwensley
Copy link
Member

cwensley commented May 1, 2024

Hey @joerih, thanks for submitting the fix and especially for the unit tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Binding.RemovePropertyEvent does not remove the 'EventHandler' subscription
2 participants