KeyboardNavigation.TabOnceActiveElement memory leak #15455
Unanswered
workgroupengineering
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I had been experiencing memory leak for some time but I couldn't identify where. Issue #15443 enlightened me.
I modified it to leave out other problems that exist and only address the one in question.
AvaloniaBugs.zip
To simulate the problem do:
New Tab
three timesClose First
If you analyze the memory snapshot, you will see that you will find three instances of
BigFileViewModel
instead of the expected two.This is because the TabStrip holds the reference to the deleted TabStripItem via the attached TabOnceActiveElement property, and in turn, the TabStripItem holds the reference to the "BigFileViewModel" via the DataContext.
I make test PR #15454 that address ItemsControl TabOnceActiveElement memory leak, but I would like to solve it in a more generic way.
I have identified two possible solutions:
In KeyboardNavigation, intercept the KeyboardNavigation PropertyChange. In the interceptor check if the IInputElement is a Viusal, if so subscribe the DetachedFromVisualTree event and set the TabOnceActiveElement to null when it is raised.
Store the value of AvaloniaProperty via WeakReference when the value is of type AvaloniaObject.
I don't know which is the best solution, and I can't answer because I don't know Avalonia so thoroughly as to be able to imagine the consequences of one of the two choices or whether there is an alternative way.
I hope this issue can be resolved before the final version of Avalonia 11.1 is released.
Beta Was this translation helpful? Give feedback.
All reactions