Skip to content

fix(responsive): release hosts that never load from HardSelfReferences (backport #1684) - #1685

Merged
kazo0 merged 1 commit into
servicing/10.0from
mergify/bp/servicing/10.0/pr-1684
Oct 27, 2026
Merged

kazo0 merged 1 commit into
servicing/10.0from
mergify/bp/servicing/10.0/pr-1684

Conversation

@mergify

@mergify mergify Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

GitHub Issue (If applicable): closes #1683

PR Type

  • Bugfix

What is the current behavior?

  • ResponsiveExtension adds itself to the static HardSelfReferences list (the uno#14502 workaround).
  • If its element never loads, the extension never connects and is never removed from that list.
  • Its unsubscribe closure holds the element strongly, so the element and everything reachable from it stay in memory. An app in a collectible AssemblyLoadContext can't unload.

What is the new behavior?

  • Both unsubscribe closures (ConnectWhenLoaded, Connect) hold the host through a WeakReference.
  • SweepDeadInstances and CleanupIfHostDisposed share one check, IsHostGone. It falls back to the target's weak reference when the extension never connected.
  • An element that never loads is collected once nothing else references it.

Reviewer's guide

  • Start here: src/Uno.Toolkit.UI/Markup/ResponsiveExtension.cs, IsHostGone and the two Disposable.Create closures.
  • Test that proves it: ResponsiveExtensionsLeakTests.NeverLoaded_Host_IsCollectible_AfterSweep. Without the fix it fails on Assert.IsFalse(hostRef.IsAlive).
  • Test change: SweepDeadInstances_Prunes_CollectedTrackedInstances now takes its baseline count after a collect and sweep, so a dead entry left by another test can't skew it.
  • Not covered by a test:
    • The weak capture in the Connect closure. The case it guards is a connected host dropped without Unloaded, which the harness can't fake.
    • A target that isn't the host, for example a ColumnDefinition on a Grid that never loads.
  • Known limitation, unchanged: the sweep only runs when another extension connects. Until then a dead entry stays in the list, but it no longer holds its element.

PR Checklist

  • Tested the changes where applicable:
    • Desktop (Windows), Skia runtime tests on net10.0-desktop
  • Updated the documentation as needed: n/a, no behaviour change to document
  • Runtime Tests and/or UI Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Contains NO breaking changes
  • Associated with an issue (GitHub or internal)
  • Commits must be following the Conventional Commits specification.

Other information

Runtime tests, desktop, Debug, filter Responsive: 12 passed, 2 failed, 7 skipped. The 2 failures are ResponsiveHelperLeakTests.Reset_TearsDown_DefaultProvider and DefaultProvider_IsCollectible_WhileXamlRootAlive. Both time out waiting for "Border loaded", and fail the same way without this change.

🤖 Generated with Claude Code


This is an automatic backport of pull request #1684 done by [Mergify](https://mergify.com).

#1684)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Steve Bilogan <[email protected]>
(cherry picked from commit 71e1615)
@kazo0
kazo0 enabled auto-merge (squash) October 27, 2026 03:07
@kazo0
kazo0 merged commit ee366de into servicing/10.0 Oct 27, 2026
19 checks passed
@kazo0
kazo0 deleted the mergify/bp/servicing/10.0/pr-1684 branch October 27, 2026 03:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants