Fixed memory leaks in ContextMenu.cs #12526
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does the pull request do?
Fixes two memory leaks -
ContextMenu
set.ItemPanel
is set toStackPanel
;' I don't know why.What is the current behavior?
Two issues:
ControlTheme
, there will be only 1 ContextMenu created for all controls of these type, but each time a control is created it will be added to_attachedControls
and will stay there forever.ContextMenu
withItemsSource
binding have anItemsPanel
asStackPanel
the items created will not be cleared. When changingItemsPanel
toVirtualizingStackPanel
there is no issue.What is the updated/expected behavior with this PR?
No memory leaks when using ContextMenu
How was the solution implemented (if it's not obvious)?
ItemsPanel
, so it usesVirtualizingStackPanel
like every other place. I saw that this line was from 2019, and I can't think of any particular reason why it needs to stay.Note - the issue when using
StackPanel
is not resolved, but I didn't have time to investigate it.Checklist
Breaking changes
Obsoletions / Deprecations
Fixed issues