-
-
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
fix: SelectingItemsControl Selection memory Leak #15446
fix: SelectingItemsControl Selection memory Leak #15446
Conversation
You can test this PR using the following package version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks good overall, but there's a slight logic change that should be fixed.
@@ -348,11 +348,11 @@ protected ISelectionModel Selection | |||
} | |||
|
|||
InitializeSelectionModel(_selection); | |||
|
|||
if (_oldSelectedItems != SelectedItems) | |||
var seletcedItems = SelectedItems; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: typo, seletcedItems
⇒ selectedItems
|
||
if (_oldSelectedItems != SelectedItems) | ||
var seletcedItems = SelectedItems; | ||
if (_oldSelectedItems.TryGetTarget(out var oldSelectedItems) || oldSelectedItems != seletcedItems) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't equivalent to the comparison before: it will now always be true as long as we have an oldSelectedItems
.
if (_oldSelectedItems.TryGetTarget(out var oldSelectedItems) || oldSelectedItems != seletcedItems) | |
_oldSelectedItems.TryGetTarget(out var oldSelectedItems); | |
if (oldSelectedItems != selectedItems) |
You can test this PR using the following package version. |
* fix: SelectingItemsControl * fix: Address review
What does the pull request do?
Avoid SelectingItemsControl memory leak
What is the current behavior?
When SelectingItemsControl or a derived control is bound to ObservableCollection, if you remove the selected item, the removed item will not be released from memory until there is a new _oldSelectedItem, this is because _oldSelectedItem holds a hard reference. If the collection contains only two items and you remove one, the removed item will never be released from memory.
What is the updated/expected behavior with this PR?
How was the solution implemented (if it's not obvious)?
Instead of a hard reference using pre allocated WeakReference.
Checklist
Breaking changes
Obsoletions / Deprecations
Fixed issues
Part of #15443