You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recently, I've upgraded to the 2.7.3 version, where I also contributed via this attached PR.
Unfortunately, the leak was not resolved, even with my above contribution. I'll try to explain the reason for that.
In order to reproduce, you can just chose a random class and add in the constructor / some initialization method the following lines:
Binding.AddPropertyEvent(viewModel, vm => vm.Checked, OnCheckedChanged);
Binding.RemovePropertyEvent(viewModel, OnCheckedChanged);
Expected Behavior
After writing the above lines, we expect the OnCheckedChanged event handler to never be invoked, as we don't have a subscription to it, as we've invoked Binding.RemovePropertyEvent for it.
Actual Behavior
The OnCheckedChanged event handler is still invoked, even after calling Binding.RemovePropertyEvent for it (the breakpoint is hit).
Specifications
Version: 2.7.3
Platform(s): WPF
Operating System(s): Windows 10, Windows 11
Reason for the issue:
In 2.7.3, your source code for the Binding.RemovePropertyEvent looks as following:
public static void RemovePropertyEvent(object obj, EventHandler<EventArgs> eh)
{
var helper = eh.Target as PropertyNotifyHelper;
if (helper != null)
{
helper.Changed -= eh;
helper.Unregister(obj);
}
}
Previously, I've contributed by adding the helper.Changed -= eh; line, but surprisingly, as I've mentioned, the leak is still there, and the event handler keeps getting invoked, even after calling this RemovePropertyEvent method.
After investigating a bit, I've discovered that the helper is null, because eh.Target is not of type PropertyNotifyHelper , but of the type of the class, where I've defined the event handler (i.e. CustomCheckBox.cs). Thus, this code:
helper.Changed -= eh;
helper.Unregister(obj);
never happens, and the subscription is kept alive.
I couldn't find any issue about it, so was wondering if you are aware of that.
A possible direction is to understand why eh.Target stopped working for WPF (assuming it used to work).
The text was updated successfully, but these errors were encountered:
Hi there,
Recently, I've upgraded to the 2.7.3 version, where I also contributed via this attached PR.
Unfortunately, the leak was not resolved, even with my above contribution. I'll try to explain the reason for that.
In order to reproduce, you can just chose a random class and add in the constructor / some initialization method the following lines:
Expected Behavior
After writing the above lines, we expect the
OnCheckedChanged
event handler to never be invoked, as we don't have a subscription to it, as we've invokedBinding.RemovePropertyEvent
for it.Actual Behavior
The
OnCheckedChanged
event handler is still invoked, even after callingBinding.RemovePropertyEvent
for it (the breakpoint is hit).Specifications
Reason for the issue:
In 2.7.3, your source code for the
Binding.RemovePropertyEvent
looks as following:Previously, I've contributed by adding the
helper.Changed -= eh;
line, but surprisingly, as I've mentioned, the leak is still there, and the event handler keeps getting invoked, even after calling thisRemovePropertyEvent
method.After investigating a bit, I've discovered that the helper is null, because
eh.Target
is not of typePropertyNotifyHelper
, but of the type of the class, where I've defined the event handler (i.e.CustomCheckBox.cs
). Thus, this code:never happens, and the subscription is kept alive.
I couldn't find any issue about it, so was wondering if you are aware of that.
A possible direction is to understand why
eh.Target
stopped working for WPF (assuming it used to work).The text was updated successfully, but these errors were encountered: