Repository navigation
fix(TreeView): prune item-to-node map on collection Reset - #23634
Merged
MartinZikmund merged 3 commits intoJul 6, 2026
Merged
MartinZikmund merged 3 commits into
MartinZikmund merged 3 commits into
Conversation
|
Nick Randolph seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Contributor
|
Tick the box to add this pull request to the merge queue (same as
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a TreeView memory leak in content mode where an ItemsSource collection Clear (translated to a CollectionChange.Reset) removes nodes from the view but leaves m_itemToNodeMap entries behind, retaining cleared items for the TreeView’s lifetime (and potentially pinning collectible AssemblyLoadContexts), per #23633.
Changes:
- On
CollectionChange.Reset, prunesm_itemToNodeMapentries whose nodes are no longer attached to the origin node. - Adds helper logic to detect nodes detached from the origin root and uses it to prune stale mappings.
- Prunes detached selections as an additional retention path (selected nodes/items surviving a reset).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
nickrandolph
force-pushed
the
dev/nr/alc-itemsview-debug-layout-leak
branch
from
July 3, 2026 13:41
e652e9f to
6d9aae0
Compare
nickrandolph
force-pushed
the
dev/nr/alc-treeview-itemmap-reset-prune
branch
from
July 3, 2026 13:42
228b181 to
cdcfce8
Compare
MartinZikmund
self-requested a review
July 3, 2026 18:28
Open
2 tasks done
The WinUI-derived collection-change handling removes m_itemToNodeMap entries only on ItemRemoved with an expanded parent. A Reset (ItemsSource collection Clear) removed the nodes from view but left every item -> node mapping behind, retaining the cleared items for the TreeView's lifetime — and when items come from a collectible AssemblyLoadContext (plugin / preview hosting), pinning that ALC. Prune mappings whose node is no longer attached to the origin node on Reset; also covers removals under a collapsed parent once any reset occurs.
Companion to the item-to-node map prune: a selected node removed via a collection Reset stayed in m_selectedNodes / m_selectedItems indefinitely, keeping the node and its item alive (dump-proven: a TreeView-based tool's selection vector retained the previous data session's items, pinning a collectible ALC). SelectedItemsVector.RemoveAt keeps both vectors in sync and raises selection-change notifications.
…lection tracking Addresses review feedback (#23633): the Reset selection-pruning removed via m_selectedItems.RemoveAt, bypassing TrackItemUnselected (RemoveAtCore can't correlate an item already gone from SelectedItems), so SelectionChanged wasn't raised in multi-select mode. Prune via m_selectedNodes.RemoveAtCore (mirrors the ItemRemoved/Reset cases), unsubscribe ChildrenChanged, and batch inside Begin/EndSelectionChanges for a single aggregate SelectionChanged. Co-Authored-By: Claude Fable 5 <[email protected]>
nickrandolph
force-pushed
the
dev/nr/alc-itemsview-debug-layout-leak
branch
from
July 6, 2026 07:37
6d9aae0 to
55cd1af
Compare
nickrandolph
force-pushed
the
dev/nr/alc-treeview-itemmap-reset-prune
branch
from
July 6, 2026 07:37
cdcfce8 to
a546bc1
Compare
MartinZikmund
approved these changes
Jul 6, 2026
MartinZikmund
merged commit Jul 6, 2026
e326d83
into
dev/nr/alc-itemsview-debug-layout-leak
10 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
ALC pin-fix stack — PR 4 of 4 (uno). Base:
dev/nr/alc-itemsview-debug-layout-leak. Top of the uno stack.Fixes #23633