Repository navigation
fix(AnimatedIcon): Don't root the icon from its Foreground brush or State ancestor - #25948
Conversation
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
d1994ea to
3b52af6
Compare
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 242999 found UI Test snapshots differences: Details
|
3b52af6 to
174c5d1
Compare
An app-lifetime Foreground brush (a theme brush) must not keep an AnimatedIcon alive, whether the icon was never loaded or was unloaded before its Foreground changed. The icon must still track the brush's Color while loaded, after a brush swap and after a reload. Co-authored-by: jbourque-kahua <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Color subscription went through the public token API, whose registration the brush holds strongly, so an app-lifetime brush (a ThemeResource) kept every icon that ever used it alive, with its DataContext. WinUI's handler doesn't own the icon; register weakly to match. Co-Authored-By: Claude Opus 5.5 <[email protected]>
An icon copies AnimatedIcon.State from the nearest ancestor that sets it and listens for changes through the public token API, which the ancestor holds strongly and nothing revokes, so a long-lived ancestor kept every icon ever loaded under it alive. Register weakly, as for the Foreground brush. Co-Authored-By: Claude Opus 5.5 <[email protected]>
174c5d1 to
38d9378
Compare
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 243009 found UI Test snapshots differences: Details
|
|
@Mergifyio backport release/stable/6.7 servicing/6.8 |
✅ Backports have been createdDetails
Cherry-pick of 6fe9b9e 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 6fe9b9e 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 |
…r-25948 fix(AnimatedIcon): Don't root the icon from its Foreground brush or State ancestor (backport #25948)
…6.7/pr-25948 fix(AnimatedIcon): Don't root the icon from its Foreground brush or State ancestor (backport #25948)
GitHub Issue: closes unoplatform/kahua-private#563
PR Type:
🐞 Bugfix
What changed? 🚀
An
AnimatedIconwhoseForegroundis a long-livedSolidColorBrush(e.g. aThemeResourcebrush) stayed in memory, together with its subtree andDataContext, for as long as the brush lived.AnimatedIconlistened to the brush'sColorthrough the publicRegisterPropertyChangedCallback, which the brush holds strongly until it's unregistered. The unload handler unregisters it, but an icon that was never loaded, or whoseForegroundchanged after it unloaded, kept a registration that nothing ever removed. The retention path isbrush → _propertyChangedTokens → callback → AnimatedIcon.The
Colorcallback now goes through the internalRegisterDisposablePropertyChangedCallback, which holds it weakly and ties it to the icon's lifetime. WinUI behaves the same way:AnimatedIcon.cppsubscribes on everyForegroundchange with a{ this, &AnimatedIcon::... }handler that doesn't own the icon.The same applies to
AnimatedIcon.State: on load, an icon copiesStatefrom the nearest ancestor that sets it and listens for that ancestor's changes. That registration was never removed, so a long-lived ancestor kept every icon ever loaded under it alive. It is now weak as well.Scope. The public
RegisterPropertyChangedCallbackstays strong: that's its contract, and apps rely on a registered lambda staying alive. The bug is using it to listen to an object that can outlive the subscriber. When porting a WinUI handler that doesn't own its subscriber and listens to such an object, useRegisterDisposablePropertyChangedCallback. Other controls use the same pattern and will be looked at separately.Known limitation. A brush keeps a strong reference to the first element it's assigned to (
_associatedParent), so a brush used by exactly one element still keeps that element alive. That's independent ofAnimatedIconand out of scope here.New runtime tests in
Given_AnimatedIcon:[PlatformCondition(Exclude, NativeWinUI)]):When_Foreground_Set_While_Never_Loaded_Then_Not_Rooted_By_Brush, with and without aSourceWhen_Foreground_Changes_After_Unload_Then_Not_Rooted_By_Brush, with and without aSourceWhen_Unloaded_From_Ancestor_With_State_Then_Not_Rooted_By_AncestorIAnimatedVisualSource2test double:When_Loaded_Then_Brush_Color_Change_Reaches_SourceWhen_Foreground_Brush_Swapped_While_Loaded_Then_New_Brush_Is_TrackedWhen_Reloaded_Then_Current_Color_Applied_And_Brush_TrackedWhen_Ancestor_State_Changes_Then_Icon_State_FollowsLocally on Skia Win32 (
SamplesAppnet10.0-desktop):Foregroundfix, the 4Foregroundleak cases fail.Statefix, its leak test fails.Given_FrameworkElement_And_Leakand theAnimatedVisualstests still pass (126/126 together withGiven_AnimatedIcon).On native WinUI (the WinAppSDK head, run locally), the 4 behavior tests pass and the 3 leak tests are skipped.
PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code