Repository navigation
fix(AnimatedIcon): Don't root the icon from its Foreground brush or State ancestor (backport #25948) - #25963
Merged
Conversation
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]> (cherry picked from commit 6fe9b9e) # Conflicts: # src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AnimatedIcon.cs
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]> (cherry picked from commit 6bcfdd7)
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]> (cherry picked from commit 38d9378)
This comment was marked as resolved.
This comment was marked as resolved.
2 of 5 tasks
Move Given_AnimatedIcon next to the other AnimatedVisual tests, matching its namespace, and implement the Uno-specific IAnimatedVisualSource members on the test's spy source, which 6.x still declares. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Xiaoy312
enabled auto-merge
November 3, 2026 19:21
Xiaoy312
approved these changes
Nov 3, 2026
Contributor
Author
|
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. |
Merged
1 task done
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.
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
This is an automatic backport of pull request #25948 done by [Mergify](https://mergify.com).