-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Button.IsCancel still works for detached button + MemoryLeak #7751
Comments
Note: This issue would also apply for I can't speak for the correctness of your solution. However, it should be easy to add the code from the OnPropertyChanged method here: Avalonia/src/Avalonia.Controls/Button.cs Lines 235 to 267 in d0f3fed
|
Now I'm thinking may be that is conceptual issue? May be events automatically should unsubsribe when element is detached? |
We'll need someone from the core team to weigh-in with how things are supposed to work. At first glance, it appears you are correct though and the button should be automatically unsubscribing when adding/removing from the logical tree -- not only when the property value changes. The Command is already handled this way. Code I would be looking to add to OnAttached/DetachedLogicalTree (or perhaps VisualTree) methods is from the OnPropertyChanged method: Avalonia/src/Avalonia.Controls/Button.cs Lines 415 to 425 in d0f3fed
|
Yes. Subscribing and unsubscribing should be done in OnAttached/Detached methods. |
Solution is to unsubscribe IsCancel in OnDetachedFromVisualTree method. |
@maxkatz6 Thanks for confirming. Since I've done some work with Button recently and know my way around this code I'll fix this one. No guarantees on timing but it will be done before 11.0. |
Describe the bug
Button.StopListeningForCancel is called only when property IsCancel is set to false and is not called when button is detached from the visual tree.
Additionally that also means that root element holds reference to the button forewer:
The text was updated successfully, but these errors were encountered: