Repository navigation
[Windows] Fix CollectionView CV2 retention after dynamic removal - #39543
Merged
kubaflo merged 1 commit intoOct 22, 2026
Merged
Conversation
Break strong owner and collection-change retention paths in Windows CV2. Tie recycled item pools to the CollectionView lifetime while preserving reuse for live owners. Add Windows CV2 device regressions for removal, grouped subscriptions, reattachment, and recycled item lifetime and rebinding.
sheiksyedm
temporarily deployed
to
copilot-pat-pool
October 22, 2026 08:19 — with
GitHub Actions
Inactive
Contributor
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 39543Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 39543" |
sheiksyedm
temporarily deployed
to
copilot-pat-pool
October 22, 2026 08:19 — with
GitHub Actions
Inactive
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
Skill Validation Results
❌ Skill Validation Results —
|
sheiksyedm
temporarily deployed
to
copilot-pat-pool
October 22, 2026 08:20 — with
GitHub Actions
Inactive
sheiksyedm
temporarily deployed
to
copilot-pat-pool
October 22, 2026 08:23 — with
GitHub Actions
Inactive
sheiksyedm
temporarily deployed
to
copilot-pat-pool
October 22, 2026 08:24 — with
GitHub Actions
Inactive
sheiksyedm
temporarily deployed
to
copilot-pat-pool
October 22, 2026 08:25 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Windows COM and garbage-collection lifetime changes need device-test validation and human review, with handler proxy cleanup still unresolved.
1 open issue
What changed in this PR
This PR addresses Windows CollectionView handler retention after dynamic removal while the host page remains open.
Changes:
- Replace strong owner references and collection-change subscriptions with weak references and proxies.
- Tie recycle-pool lifetime to the owning CollectionView.
- Add device tests for collection, reattachment, live updates, and recycling.
| File | Description |
|---|---|
| src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionView2MemoryTests.Windows.cs | Adds lifetime and continued-functionality regression tests. |
| src/Controls/src/Core/Handlers/Items2/Windows/ObservableItemTemplateCollection2.cs | Weakly references the owner and guards notifications. |
| src/Controls/src/Core/Handlers/Items2/Windows/ItemTemplateContextList2.cs | Uses a weak owner reference for cached contexts. |
| src/Controls/src/Core/Handlers/Items2/Windows/ItemTemplateContextEnumerable2.cs | Passes a weak owner reference into enumerated contexts. |
| src/Controls/src/Core/Handlers/Items2/Windows/ItemTemplateContext2.cs | Supports sharing an existing weak owner reference. |
| src/Controls/src/Core/Handlers/Items2/Windows/ItemFactory.cs | Weakly references the owner and scopes recycle-pool retention to its lifetime. |
| src/Controls/src/Core/Handlers/Items2/Windows/GroupedItemTemplateCollection2.cs | Adds weak subscriptions, retained callbacks, and finalizer cleanup. |
| src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.Windows.cs | Replaces direct collection-change subscriptions with a weak proxy. |
Review effort: Balanced
Comment on lines
+70
to
+71
| WeakNotifyCollectionChangedProxy? _itemsChangedProxy; | ||
| NotifyCollectionChangedEventHandler? _itemsChanged; |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This was referenced Oct 22, 2026
kubaflo
approved these changes
Oct 22, 2026
3 of 4 tasks
This branch was previously deployed
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.

Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Issue details
Dynamically removing a CollectionView from a page could leave the managed CollectionView, its handler, native collection control, and realized item content alive after repeated garbage collection and UI idle.
In the source-built baseline, 180 dynamic add/remove cycles retained all 180 removed native collection controls. The host page remained open during this scenario.
The investigation identified several retaining paths:
Fresh navigation-only testing did not show the same progressive native retention. Dynamic removal while the host remained alive was the primary reproduced failure.
Fix details
The fix does not require application-side handler disconnection or manual cleanup. Existing virtualization, layout, template selection, and recycling algorithms are preserved.