Repository navigation
fix(composition): Prune dead context entries on add - #26124
Conversation
CompositionObject.AddContext appended a weak ContextEntry per consumer but never swept dead ones. A consumer (BorderVisual, CompositionSpriteShape, SpriteVisual) only removes its entry when its brush property is reassigned, so consumers that are simply collected left their entry on the brush. Shared theme/resource brushes rarely raise changes (PropagateChanged is the only other place that prunes), so their list and its WeakReference GC handles grew without bound (3 entries per Border+Rectangle using the brush). AddContext now sweeps dead entries once the list reaches a threshold, then resets the threshold to twice the surviving count (min 16): O(live consumers) size, amortized O(1) per add. The sweep is skipped while PropagateChanged is iterating the same list. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conservative GC (WASM, mobile) can keep a consumer alive, which then legitimately keeps its entry. Derive the expected counts from the measured survivors instead of assuming every consumer was collected, and fail visibly if most of them were not. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The XAML leak test now asserts the live Border and Rectangle keep their entries and still render a brush change after the sweep, and resets the window content. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@Mergifyio backport release/stable/6.7 servicing/6.8 |
✅ Backports have been createdDetails
Cherry-pick of b393072 has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally
Cherry-pick of b393072 has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally |
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-26124/docs/index.html |
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 244220 found UI Test snapshots differences: Details
|
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
…r-26124 fix(composition): Prune dead context entries on add (backport #26124)
…6.7/pr-26124 fix(composition): Prune dead context entries on add (backport #26124)
GitHub Issue: closes unoplatform/kahua-private#569
PR Type:
🐞 Bugfix
What changed? 🚀
A composition brush keeps a weak "context" entry (a
WeakReferenceand its GC handle) for every visual or shape that uses it, so it can propagate its changes. A consumer only removes its entry when its brush property is reassigned. Consumers that are simply unloaded and collected left their entry on the brush, and only a change of the brush pruned them. Shared theme/resource brushes rarely change, so their list grew without bound: 3 entries per Border + Rectangle that ever used the brush.CompositionObject.AddContextnow sweeps dead entries once the list reaches a threshold, then resets the threshold to twice the surviving count (minimum 16). The sweep is skipped whilePropagateChangedwalks the same list.Given_CompositionObject_Context. They fail without the fix (1000 / 1050 / 303 entries) and pass with it. The expected counts include any consumers the GC failed to collect (conservative stack scanning on WASM / mobile), and a test fails visibly if more than 10% stay alive. The XAML test also checks that the live Border and Rectangle still render a brush change after the sweep.CompositionBrushContextLeakin SamplesApp.The fix commit is the reporter's patch, kept verbatim; follow-ups are separate commits.
PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code