Repository navigation
[Mac Catalyst] Memory tests: Fix asynchronous and native lifetime cleanup - #37278
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 37278Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 37278" |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
|
/azp run maui-pr-uitests , maui-pr-devicetests |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
This comment has been minimized.
This comment has been minimized.
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 5 findings
See inline comments for details.
| #if TESTS_FAILS_ON_WINDOWS // For more information, see: https://github.com/dotnet/maui/issues/35985 | ||
| [Fact] | ||
| [Category(TestCategory.RadioButton)] | ||
| public async Task RadioButtonHandlerShouldNotLeak() |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[major] Regression Prevention / Test Reliability — This test is re-enabled by deleting the #if TESTS_FAILS_ON_WINDOWS guard, but nothing else in the PR changes: no product fix, no test-lifetime fix, no teardown change. The only substantive fix in this PR (awaiting AttachAndRun) is in the iOS/Catalyst CALayerAutosizeToSuperLayerBehaviorTests; RadioButtonHandlerShouldNotLeak is byte-for-byte the code that was failing under #35985/#36614 after WaitForGC was strengthened in #35487. Concrete scenario: if the Windows retention is a real product leak (e.g. the RadioButtonGroup attached-property/group-controller registration created by lines 90-92 keeping the handler/platform view rooted), this re-enable puts the Windows device-test lane back to red on merge.
Also note the guard symbol TESTS_FAILS_ON_WINDOWS is never defined in any csproj/props/targets in this repo, so the test was actually disabled on all platforms (Android, iOS, MacCatalyst, Windows) — removing it re-enables it everywhere, not just on Windows. Please either (a) attach the Windows and Android/iOS/Catalyst device-test evidence showing it now passes, or (b) include the lifetime/product fix that makes it pass. "Did not reproduce locally" is not sufficient evidence for a test that was disabled because it failed in CI.
|
|
||
| #if TESTS_FAILS_ON_WINDOWS // For more information, see: https://github.com/dotnet/maui/issues/35985 | ||
| [Fact(DisplayName = "MauiWinUIWindow doesn't leak")] | ||
| public async Task MauiWinUIWindowDoesntLeak() |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[major] Regression Prevention / Test Reliability — Same concern as RadioButtonHandlerShouldNotLeak: the guard is removed with no accompanying change to the test body or to Window teardown, so the exact code that failed under #35985/#36614 is re-enabled unchanged.
This test is additionally environment-sensitive in a way this file already documents: the trailing comment at lines 384-386 states that MinimizeAndThenMaximizingWorks was moved out of device tests because "window activation events don't fire reliably on Helix VMs which run in non-interactive Windows sessions". MauiWinUIWindowDoesntLeak calls window.Activate() (line 67) and then relies on window.Close() completing teardown within a fixed await Task.Delay(100) (line 68). On a non-interactive Helix session, activation/close message pumping is precisely what is unreliable, so WinUI can still hold the last-activated/closing MauiWinUIWindow when WaitForGC runs. Please either wait deterministically on an observable teardown signal (e.g. the window's Closed/Destroying event with AssertEventually) instead of Task.Delay(100), or provide a Windows device-test run showing this is now stable across repeated runs.
|
|
||
| // Use the standard WaitForGC pattern which tries up to 40 GC cycles with Task.Yield | ||
| // This is the same approach used by all other memory leak tests in the repo | ||
| await AssertionExtensions.WaitForGC(weakReferences.ToArray()); |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[moderate] Async and Threading Safety / Test Reliability — WaitForGC is asserted inside the CreateHandlerAndAddToWindow callback, i.e. while the outer test window/handler is still alive and while each MauiWinUIWindow's Close() teardown may still be in flight (only a fixed 100 ms delay separates Close() from the assert). WaitForGC runs 40 GC cycles with only Task.Yield() between them; Task.Yield() on the WinUI dispatcher does pump, but nothing here guarantees the XAML framework has released its reference to the most recently activated/closed window before the 40 cycles are exhausted. Concrete failure mode: the third MauiWinUIWindow (the last one activated) is still rooted by WinUI and the assert fails non-deterministically, exactly the "some are still alive" failure recorded in #36614. Consider asserting the last window's collection after its Closed event has actually been observed, or moving the WaitForGC outside the callback so the whole window scope has been torn down first.
| public class MauiCALayerAutosizeToSuperLayerBehaviorTests : TestBase | ||
| { | ||
| #if TESTS_FAILS_ON_MACCATALYST // For more information, see: https://github.com/dotnet/maui/issues/35985 | ||
| [Theory] |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[moderate] Platform-Specific Code Scoping / Regression Prevention — The removed guard was named TESTS_FAILS_ON_MACCATALYST, but the symbol is never defined in any csproj/props/targets and this file is compiled under #if IOS || MACCATALYST (line 1). The test was therefore disabled on iOS as well as MacCatalyst, and this change newly enables it on iOS. The await AttachAndRun(...) fix below is a genuine correctness fix (the un-awaited call let WaitForGC run before AttachAndRun's finally executed view.RemoveFromSuperview() / attachedView.RemoveFromSuperview()), so the change is directionally right — but please state explicitly whether the iOS lane was validated too, since the guard's name implies only MacCatalyst was ever assessed.
| await view.AttachAndRun(() => view.Frame = new CoreGraphics.CGRect(0, 0, 200, 200)); | ||
| }); | ||
|
|
||
| await AssertionExtensions.WaitForGC(viewReference, layerReference, sublayerReference); |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[moderate] Memory Leak Prevention (iOS/MacCatalyst) — Awaiting AttachAndRun is the correct fix for the detach race, but WaitForGC still runs on the xunit thread immediately after the main-thread block returns. On iOS/MacCatalyst the UIView, its CALayer and the added sublayer can still be retained by the main thread's autorelease pool / a pending layout pass that has not been drained: AttachAndRun only gives a fixed await Task.Delay(100) after RemoveFromSuperview() (AssertionExtensions.iOS.cs:167-171), which is best-effort rather than deterministic. If this test proves flaky on the iOS/Catalyst lanes, the fix is to hop back to the main thread once (e.g. an additional await InvokeOnMainThreadAsync(() => { }) / run-loop drain) before asserting, rather than relaxing the GC assertion. Flagging for author confirmation with an actual iOS+MacCatalyst device-test run, since local Gate verification for this PR was inconclusive.
|
/azp run maui-pr-uitests , maui-pr-devicetests |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
This comment has been minimized.
This comment has been minimized.
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 3 findings
See inline comments for details.
| { | ||
| platformView.Checked -= OnCheckedOrUnchecked; | ||
| platformView.Unchecked -= OnCheckedOrUnchecked; | ||
| platformView.GroupName = string.Empty; |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[major] Handler Mapper and Property Patterns / Memory Leak Prevention — This cleanup only runs from IElementHandler.DisconnectHandler(), which the re-enabled RadioButtonHandlerShouldNotLeak test never invokes: that test builds the tree with CreateHandler<LayoutHandler>(layout) (no window, no teardown disconnect) and then goes straight to WaitForGC. So for the normal GC-driven teardown path this line is a no-op, and if the WinUI group registration really is the root that pins the native RadioButton (unique GUID group assigned in CreatePlatformView, per the #11418 workaround), every radio button whose handler is never explicitly disconnected still leaks. Local gate evidence also reports RadioButtonTests on Windows at 6 passed / 1 failed with this fix applied, which is consistent with the leak root not being addressed here. Please establish the actual retaining root (e.g. capture the GC root path for the pinned RadioButton) and add coverage that exercises the code path being changed — otherwise this is an unverified defensive edit shipped alongside an unrelated real fix.
Secondary concern on the chosen value: GroupName = string.Empty does not just unregister — in WinUI an empty group name puts the control back into the implicit parent-scoped grouping. If the native view is still parented when the handler disconnects (handler disconnect does not remove the platform view from its parent), two or more disconnected MAUI radio buttons under the same panel become mutually exclusive again, which is exactly what the unique-GUID workaround exists to prevent; a checked one being cleared last can flip a sibling's native IsChecked. Note also that the GUID is only assigned in CreatePlatformView, so nothing re-establishes a unique group if a platform view is ever reused.
| #endif | ||
|
|
||
| #if TESTS_FAILS_ON_WINDOWS // For more information, see: https://github.com/dotnet/maui/issues/35985 | ||
| [Fact] |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[moderate] Regression Prevention and Test Coverage — Re-enabling this test does not validate the accompanying RadioButtonHandler.Windows.cs change: the test never calls DisconnectHandler() (no window is created, so the ControlsHandlerTestBase.Windows teardown disconnect does not apply), so the new GroupName = string.Empty line is never executed here. Whatever makes this test pass now is therefore a different root cause (most plausibly the MauiWinUIWindow.WindowMessage unsubscription in this same PR). Please either add an assertion/scenario that actually disconnects the RadioButton handler, or drop the handler change from this PR so the fix and its evidence line up. Note also that TESTS_FAILS_ON_WINDOWS is not defined in any props/targets, so removing the guard re-enables this test on all platforms (Android/iOS/Mac too), not just Windows — confirm it is green there as well before merge.
| Closed -= OnClosedPrivate; | ||
| VisibilityChanged -= OnVisibilityChanged; | ||
| _viewSettings.ColorValuesChanged -= ViewSettingsColorValuesChanged; | ||
| _windowManager.WindowMessage -= OnWindowMessage; |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[moderate] Cross-Platform Behavioral Consistency / Public behavior change — The leak fix itself is correct (the WindowMessage subscription rooted this through the WindowMessageManager, and hoisting the local function to an instance method makes -= reference-equal). But unsubscribing inside OnClosedPrivate also stops WindowsLifecycle.OnPlatformMessage from being invoked for every message delivered after Window.Closed — notably WM_DESTROY / WM_NCDESTROY and the tail of the shutdown sequence. Apps that hook OnPlatformMessage for shutdown/native-cleanup work will silently stop receiving those messages; this is an observable behavior change that deserves either a deliberate call-out in the PR description/release notes or unsubscribing on WM_NCDESTROY instead of on Closed.
Secondary: cleanup is still tied to the Closed event, so a MauiWinUIWindow that is constructed and abandoned without being closed keeps the same subscription (and therefore the same leak). That matches the pre-existing pattern for the other -= calls here, but it means the re-enabled MauiWinUIWindowDoesntLeak test (which always calls window.Close()) only covers the closed path.
|
/azp run maui-pr-uitests , maui-pr-devicetests |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
kubaflo
left a comment
There was a problem hiding this comment.
Is this one ready for review?
This comment has been minimized.
This comment has been minimized.
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 3 findings
See inline comments for details.
| #if TESTS_FAILS_ON_WINDOWS // For more information, see: https://github.com/dotnet/maui/issues/35985 | ||
| [Fact] | ||
| [Category(TestCategory.RadioButton)] | ||
| public async Task RadioButtonHandlerShouldNotLeak() |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[critical] Regression Prevention and Test Coverage — This test is re-enabled, but the only production change for Windows RadioButton (RadioButtonHandler.Windows.cs: platformView.GroupName = string.Empty;) lives in DisconnectHandler, and this test never disconnects anything. It builds the Grid/RadioButton tree, calls CreateHandler<LayoutHandler>(layout), captures weak references, and then goes straight to AssertionExtensions.WaitForGC(...). IElementHandler.DisconnectHandler() is never invoked on the RadioButton handler (no DisconnectHandlers() call, no removal from the layout, no window teardown in this test), so the new GroupName reset cannot execute on this code path and nothing that roots the platform RadioButton is released. Concrete failure: on Windows this test goes from skipped to failing at WaitForGC (line 102) with the same leak reported in #35985 — which matches the reported still-failing run. Either the fix must clear the WinUI group registration on a path this scenario actually hits (e.g. at platform-view teardown / when the view leaves the tree), or the test must explicitly disconnect the handler before WaitForGC and that disconnect must be the behavior being asserted.
| { | ||
| platformView.Checked -= OnCheckedOrUnchecked; | ||
| platformView.Unchecked -= OnCheckedOrUnchecked; | ||
| platformView.GroupName = string.Empty; |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[major] Handler Mapper and Property Patterns / Memory Leak Prevention — Two mechanical problems with clearing GroupName here:
-
Coverage gap.
DisconnectHandlerruns only when something explicitly callsIElementHandler.DisconnectHandler(). In the common path where aRadioButtonand its handler are simply dropped (page/layout released without an explicit disconnect — exactly what the re-enabledRadioButtonHandlerShouldNotLeakexercises), this line never executes, so whatever holds the platform view via the GUID group registration still holds it. The fix removes the root only for callers that disconnect. -
Asymmetry / no restore. The unique group name is assigned once, in
CreatePlatformView()(line 12, the Radio button loses initial 'IsChecked=True' value when another radio button also has 'IsChecked=True' #11418 workaround). There is noGroupNamemapper andConnectHandlerdoes not re-assign it, so once this line setsGroupNameto empty the platform view can never regain a unique group. Any platformRadioButtonthat outlives its handler while still parented (e.g.DisconnectHandlers()invoked on a subtree that stays in the visual tree) falls back to WinUI's implicit parent-based grouping, re-introducing the cross-talk Radio button loses initial 'IsChecked=True' value when another radio button also has 'IsChecked=True' #11418 was working around. If this reset is kept, assign the unique GUID group name inConnectHandler(idempotently) rather than only inCreatePlatformView, so connect/disconnect are symmetric.
| Closed -= OnClosedPrivate; | ||
| VisibilityChanged -= OnVisibilityChanged; | ||
| _viewSettings.ColorValuesChanged -= ViewSettingsColorValuesChanged; | ||
| _windowManager.WindowMessage -= OnWindowMessage; |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[moderate] Backward Compatibility and Migration — Unsubscribing _windowManager.WindowMessage inside OnClosedPrivate also silently truncates the public WindowsLifecycle.OnPlatformMessage lifecycle event, which is raised at the end of OnWindowMessage. Window.Closed fires before the HWND is destroyed, so after this line every subsequent Win32 message for this window — including WM_DESTROY/WM_NCDESTROY and any shutdown-time messages — is no longer forwarded to app code registered via ConfigureLifecycleEvents(... OnPlatformMessage ...). Apps that do teardown work keyed off those messages stop receiving them. If the goal is only to break the delegate reference from the (longer-lived) message manager to the window, consider unsubscribing after destruction (e.g. on WM_NCDESTROY inside OnWindowMessage) so no message is dropped, or document the truncation as intended.
MauiBot
left a comment
There was a problem hiding this comment.
AI Review Summary
@devanathan-vaithiyanathan — new AI review results are available based on commit
52837e5.
🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix
Gate Result: ❌ FAILED
Platform: WINDOWS · Base: main · Merge base: abdfbef0
🩺 Fix breaks tests — one or more tests fail with the fix applied, and none of the failures are resolved by the fix.
⚠️ Gate coverage limitations
- The A/B gate did not verify 1 dropped DeviceTest group(s): WindowTests (MauiWinUIWindowDoesntLeak). Deep UI Tests runs HostApp UI categories only and does not execute DeviceTests; separate device-test validation is required.
| Test | Without Fix (expect FAIL) | With Fix (expect PASS) |
|---|---|---|
📱 MauiCALayerAutosizeToSuperLayerBehaviorTests (MauiCALayerAutosizeToSuperLayerBehavior_DoesNotLeak) Category=Memory |
||
📱 RadioButtonTests (RadioButtonHandlerShouldNotLeak) Category=RadioButton |
✅ FAIL — 308s | ❌ FAIL — 898s |
🔴 Without fix — 📱 MauiCALayerAutosizeToSuperLayerBehaviorTests (MauiCALayerAutosizeToSuperLayerBehavior_DoesNotLeak): ⚠️ ENV ERROR · 368s
No log file found
🟢 With fix — 📱 MauiCALayerAutosizeToSuperLayerBehaviorTests (MauiCALayerAutosizeToSuperLayerBehavior_DoesNotLeak): ⚠️ ENV ERROR · 280s
No log file found
🔴 Without fix — 📱 RadioButtonTests (RadioButtonHandlerShouldNotLeak): FAIL ✅ · 308s
(no coded error found; showing last 1200 chars)
ss the warning by specifying `x:SuppressXamlTrimWarnings=True` within the closest element. If not, the property path might be trimmed and will not be AOT compatible. [D:\a\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.19041.0]
Platform\Windows\TabbedPage\TabbedPageStyle.xaml(13,13): XamlCompiler warning WMC1510: Ensure the property path is trimming and AOT compatible by making use of 'Compiled Bindings (x:bind)' if possible or by specifying the 'x:DataType' directive with the respective binding data context and marking the type declaration with the 'WinRT.GeneratedBindableCustomProperty' attribute or the 'Microsoft.UI.Xaml.Data.Bindable' attribute. If you are unable to do either but can ensure the data type is attributed correctly, then you can also suppress the warning by specifying `x:SuppressXamlTrimWarnings=True` within the closest element. If not, the property path might be trimmed and will not be AOT compatible. [D:\a\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.19041.0]
0 Error(s)
Time Elapsed 00:04:49.53
Passed: 0
Failed: 1
Skipped: 0
Total: 1
Tests completed with exit code: 1
🟢 With fix — 📱 RadioButtonTests (RadioButtonHandlerShouldNotLeak): FAIL ❌ · 898s
(no coded error found; showing last 1200 chars)
ss the warning by specifying `x:SuppressXamlTrimWarnings=True` within the closest element. If not, the property path might be trimmed and will not be AOT compatible. [D:\a\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.19041.0]
Platform\Windows\TabbedPage\TabbedPageStyle.xaml(13,13): XamlCompiler warning WMC1510: Ensure the property path is trimming and AOT compatible by making use of 'Compiled Bindings (x:bind)' if possible or by specifying the 'x:DataType' directive with the respective binding data context and marking the type declaration with the 'WinRT.GeneratedBindableCustomProperty' attribute or the 'Microsoft.UI.Xaml.Data.Bindable' attribute. If you are unable to do either but can ensure the data type is attributed correctly, then you can also suppress the warning by specifying `x:SuppressXamlTrimWarnings=True` within the closest element. If not, the property path might be trimmed and will not be AOT compatible. [D:\a\1\s\src\Controls\src\Core\Controls.Core.csproj::TargetFramework=net10.0-windows10.0.19041.0]
0 Error(s)
Time Elapsed 00:04:46.81
Passed: 0
Failed: 1
Skipped: 0
Total: 1
Tests completed with exit code: 1
⚠️ Failure Details
⚠️ MauiCALayerAutosizeToSuperLayerBehaviorTests (MauiCALayerAutosizeToSuperLayerBehavior_DoesNotLeak) without fix:Device test result file(s) contained no tests for class(es) 'Microsoft.Maui.DeviceTests.Memory.MauiCALayerAutosizeToSuperLayerBehaviorTests' (the target tests did not run). Total tests found in result file(s): 0.⚠️ MauiCALayerAutosizeToSuperLayerBehaviorTests (MauiCALayerAutosizeToSuperLayerBehavior_DoesNotLeak) with fix:Device test result file(s) contained no tests for class(es) 'Microsoft.Maui.DeviceTests.Memory.MauiCALayerAutosizeToSuperLayerBehaviorTests' (the target tests did not run). Total tests found in result file(s): 0.- ❌ RadioButtonTests (RadioButtonHandlerShouldNotLeak) FAILED with fix (should pass)
Device tests: 1 of 1 failed
📁 Fix files reverted (2 files)
src/Core/src/Handlers/RadioButton/RadioButtonHandler.Windows.cssrc/Core/src/Platform/Windows/MauiWinUIWindow.cs
📋 Pre-Flight — Context & Validation
PR #37278 Pre-Flight
Context
- PR:
[WIP][Windows/Mac Catalyst] Memory tests: Fix asynchronous and native lifetime cleanup - State: Open
- Base / review head:
mainat merge baseabdfbef0e91622ef4b1cceb4897c236f7452f428/ synthetic review commit326d557701fa07826e65f42722c0461980db4be6 - Issue: #36614 reports that stricter
AssertionExtensions.WaitForGCbehavior exposed three device-test lifetime failures:RadioButtonHandlerShouldNotLeakandMauiWinUIWindowDoesntLeakon Windows, plusMauiCALayerAutosizeToSuperLayerBehavior_DoesNotLeakon Mac Catalyst. - Host platform: Windows.
- Gate: Failed. Do not rerun it.
RadioButtonHandlerShouldNotLeakfailed both without and with the PR fix. The gate could not execute the Mac Catalyst test on Windows and did not executeMauiWinUIWindowDoesntLeak.
Direct Diff Assessment
The PR changes five files:
src/Core/src/Handlers/RadioButton/RadioButtonHandler.Windows.cs- Clears the native WinUI
RadioButton.GroupNameduringDisconnectHandler. - This is intended to remove the native radio-button group registration, but the targeted test still failed with this fix.
- Clears the native WinUI
src/Core/src/Platform/Windows/MauiWinUIWindow.cs- Converts
OnWindowMessagefrom a local function to an instance method. - Unsubscribes it from
_windowManager.WindowMessageinOnClosedPrivate.
- Converts
src/Core/tests/DeviceTests/Memory/CALayerAutosizeToSuperLayerBehaviorTests.cs- Awaits
AttachAndRun, ensuring its native hierarchy cleanup completes beforeWaitForGC. - Removes the Mac Catalyst failure guard. This test cannot run on the Windows host.
- Awaits
src/Controls/tests/DeviceTests/Elements/RadioButton/RadioButtonTests.cs- Removes the failure guard from
RadioButtonHandlerShouldNotLeak.
- Removes the failure guard from
src/Controls/tests/DeviceTests/Elements/Window/WindowTests.Windows.cs- Removes the failure guard from
MauiWinUIWindowDoesntLeak.
- Removes the failure guard from
The candidate problem is therefore the Windows native lifetime cleanup. Each candidate must differ at the mechanism/root-cause level from both current PR changes: clearing GroupName during handler disconnect and unsubscribing the window-message instance handler during window close. Candidate 2 must also differ from candidate 1 based on its recorded result.
Bounded Test Surface
Use only this targeted Windows device-test command:
pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 -Project Controls -Platform windows -IncludeClasses "Microsoft.Maui.DeviceTests.RadioButtonTests,Microsoft.Maui.DeviceTests.WindowTests" -IncludeMethods "RadioButtonHandlerShouldNotLeak,MauiWinUIWindowDoesntLeak" -Rebuild- Primary test:
Microsoft.Maui.DeviceTests.RadioButtonTests.RadioButtonHandlerShouldNotLeak - Mandatory regression test:
Microsoft.Maui.DeviceTests.WindowTests.MauiWinUIWindowDoesntLeak - One implementation/test pass and at most one focused correction/retest per candidate.
- Do not run the gate, a full suite, or the Mac Catalyst test.
- The try-fix baseline-state allow-list is authoritative. Inspect other files read-only; do not edit outside
RevertedFiles. - Preserve all unrelated pre-existing worktree changes and restore only through
pwsh .github/scripts/EstablishBrokenBaseline.ps1 -Restore. - Perform the try-fix skill's inline expert self-review; do not launch another reviewer agent.
🔬 Code Review — Deep Analysis
Code Review — PR #37278
Independent Assessment
What this changes: The submitted patch awaits Mac Catalyst native-view attachment cleanup before asserting collection, removes failure guards from three memory tests, clears a WinUI RadioButton's generated native GroupName during handler disconnect, and detaches MauiWinUIWindow from WindowMessageManager.WindowMessage when the window closes.
Inferred motivation: The stricter WaitForGC implementation exposed one asynchronous test-lifetime race and two Windows native retention paths.
Reconciliation with PR Narrative
The narrative accurately describes the submitted code and explicitly acknowledges that RadioButtonHandlerShouldNotLeak still fails. That failure is material: the submitted RadioButton cleanup is in DisconnectHandler, but the re-enabled test never disconnects the handler, so the test cannot validate or benefit from the new line. The awaited AttachAndRun change is mechanically sound for the Mac Catalyst race. The window-message unsubscription breaks a concrete retaining edge, but its placement at Closed can stop forwarding later shutdown messages through the public Windows lifecycle hook.
Prior Review Reconciliation
| Prior error-level finding | Status | Evidence |
|---|---|---|
OnWindowMessage was a local function and could not be referenced by OnClosedPrivate |
Fixed | Current PR head hoists OnWindowMessage to an instance method, so the -= expression compiles. |
| RadioButton cleanup is not reached by the re-enabled leak test | Unresolved | The test creates handlers and immediately calls WaitForGC; it never invokes DisconnectHandler. The trusted Gate still fails with the submitted fix. |
Clearing GroupName can restore implicit parent grouping and is not restored on reconnect |
Unresolved | CreatePlatformView assigns the GUID only once; ConnectHandler does not restore it after DisconnectHandler writes string.Empty. |
Blast Radius Assessment
- Runs for all instances: The RadioButton change runs for every explicitly disconnected Windows RadioButton; the window change runs for every closed
MauiWinUIWindow. - Startup impact: None.
- Static/shared state: No new static state is introduced, but both changes interact with longer-lived native registration/event state.
- Lifecycle impact: The RadioButton path is asymmetric across disconnect/reconnect, and the window unsubscription changes which post-
Closednative messages can reach lifecycle subscribers.
CI Status
- Required-check query: Unavailable because
ghis unauthenticated; no clean-CI conclusion is inferred. - Trusted Gate: Failed.
- Classification: PR-caused functional failure.
RadioButtonHandlerShouldNotLeakfailed both without and with the submitted fix. The Mac Catalyst test could not run on this Windows host, andMauiWinUIWindowDoesntLeakwas not exercised by the Gate. - Action: Do not rerun the Gate. Confidence is capped at low.
Findings
❌ Error — Re-enabled RadioButton regression test still fails
src/Controls/tests/DeviceTests/Elements/RadioButton/RadioButtonTests.cs:62 re-enables a test whose exercised path never calls the newly changed DisconnectHandler. The trusted Gate confirms the unchanged failure at WaitForGC.
❌ Error — RadioButton cleanup is both unreachable for the failing scenario and asymmetric
src/Core/src/Handlers/RadioButton/RadioButtonHandler.Windows.cs:27 only clears GroupName after explicit disconnect. It therefore cannot fix the GC-only path under test. If disconnect/reconnect occurs while the native view survives, the unique GUID created to preserve #11418 behavior is replaced with string.Empty and never restored, allowing implicit parent grouping to resume.
⚠️ Warning — Closing a window can truncate native lifecycle-message forwarding
src/Core/src/Platform/Windows/MauiWinUIWindow.cs:108 unsubscribes at Window.Closed. Native messages delivered later in HWND teardown, including destruction messages, can no longer flow through WindowsLifecycle.OnPlatformMessage. The retention fix should detach at the last required native message or otherwise preserve the established lifecycle contract.
Failure-Mode Probing
- GC without explicit handler disconnect: The new RadioButton cleanup is never called; the same handler/platform/layout graph remains retained, as demonstrated by the Gate.
- Disconnect followed by reconnect: Event handlers are restored, but the generated native group identity is not; native sibling grouping can differ from the connected handler's initial behavior.
- Disconnect while still parented: Setting
GroupNameto empty opts the native control back into parent-scoped grouping while managed checked/unchecked callbacks have already been removed. - Window shutdown after
Closed: The manager no longer forwards subsequent Win32 messages toOnPlatformMessagesubscribers. - Mac Catalyst attachment cleanup: Awaiting
AttachAndRunensures itsfinally-based hierarchy removal completes beforeWaitForGC; no defect was found in that change.
External Output Contract
Not applicable.
Verdict: NEEDS_CHANGES
Confidence: low
Summary: The Mac Catalyst fix is sound and the window unsubscription addresses a plausible retention edge, but the submitted RadioButton fix does not execute in the re-enabled failing scenario and the trusted Gate proves that regression remains. The Windows lifecycle changes also need a shutdown-message-preserving teardown point or explicit contract justification.
🛠️ Try-Fix — Analysis & Comparison
PR #37278 — Try-Fix Aggregate
Candidate 1 — Blocked (baseline precondition; no code change, no test run)
PR #37278 — Try-Fix Candidate 1
Result: Blocked (environment/precondition blocker at try-fix Step 2; no production code was modified, no test was executed)
Approach and mechanism-level difference from the current PR
Designed approach — "Creation-time avoidance of the WinUI native group registration" (documented in
try-fix/attempt-1/approach.md; not applied, see blocker below).
Root-cause hypothesis: RadioButtonHandler.CreatePlatformView() on Windows unconditionally stamps every
native Microsoft.UI.Xaml.Controls.RadioButton with a per-instance GUID GroupName (a workaround for
#11418, where WinUI implicitly groups siblings sharing a parent panel). Assigning GroupName
inserts the control into WinUI's process-wide, static, group-name-keyed bookkeeping, which is pruned only
lazily — when another member of the same group is checked. Because each MAUI radio button gets a
unique GUID group, its bucket has exactly one member, is never re-walked, and is never pruned. The
platform view therefore stays reachable from a static root, and through the platform-view ↔ handler
association so do the RadioButtonHandler, the parent LayoutPanel, and the LayoutHandler — precisely
the four weak references RadioButtonHandlerShouldNotLeak asserts on.
Planned change, confined to src/Core/src/Handlers/RadioButton/RadioButtonHandler.Windows.cs:
- Stop assigning a native
GroupNameinCreatePlatformView(), so the static WinUI group table is never
touched and no static entry is ever created. - Move exclusivity arbitration entirely to the already-authoritative cross-platform
RadioButtonGroupController, which the handler already feeds via the existing
OnCheckedOrUnchecked→VirtualView.IsCheckedbridge; to preserve #11418 behaviour the handler
re-assertsPlatformView.IsCheckedfromVirtualView.IsCheckedwhenever the platform toggles a value
the cross-platform controller did not request, so native parent-scoped grouping can never win.
Prior approaches avoided. The current PR contains two changes that share one root-cause hypothesis —
remove the offending registration at teardown time:
RadioButtonHandler.Windows.cs:platformView.GroupName = string.Empty;inDisconnectHandler.MauiWinUIWindow.cs:OnWindowMessagepromoted from a local function to an instance method and
unsubscribed via_windowManager.WindowMessage -= OnWindowMessageinOnClosedPrivate.
The completed gate shows the first one does not work: RadioButtonHandlerShouldNotLeak failed both
without the fix and with the PR fix applied. The defeating mechanism is that mutating GroupName is a
re-registration, not a removal — the control moves from the GUID bucket into the empty/parent-scoped
bucket (itself a static root), while the stale GUID bucket is never purged because nothing else ever
checks a button in it.
Mechanism-level difference (cause → effect). This candidate never plants the static root instead of
trying to remove it afterwards. Because no GroupName is ever set, no entry is ever added to the static
group table; because there is no entry, nothing depends on WinUI's lazy per-group purge; therefore the
teardown path the PR relies on is never consulted at all, and the platform view becomes unreachable as
soon as the visual tree drops it. It is not the PR's clearing moved to another call site — it removes the
registration's existence, and relocates the behaviour the registration was working around to a different
architectural layer (cross-platform group controller instead of native WinUI grouping).
MauiWinUIWindow.cs is deliberately left untouched; MauiWinUIWindowDoesntLeak would serve purely as the
regression check against the unmodified file.
Files changed
None. No production or test file was modified. git status --porcelain --untracked-files=no -- src/
returns 0 lines. The only files created are attempt artifacts under
CustomAgentLogsTmp/PRState/37278/PRAgent/.
Captured diff
Explicitly empty. fix.diff (and reviewer-findings.diff) are 0-byte files — there is no code diff
for this candidate.
(empty diff — no source changes)
Blocker analysis
Step 2 of the try-fix skill mandates pwsh .github/scripts/EstablishBrokenBaseline.ps1. It was executed;
full output is in try-fix/attempt-1/baseline.log. It aborted:
ERROR: DIRTY WORKING DIRECTORY - Cannot establish baseline
EstablishBrokenBaseline.ps1 failed: Working directory is not clean. Clean up before establishing baseline.
The 55 dirty tracked files are all pre-existing, unrelated, harness-owned paths under .github/scripts/,
.github/skills/, and eng/scripts/ — none under src/. The script exposes only -BaseBranch,
-DryRun, and -Restore; there is no force/skip switch, and the only way to satisfy its clean-tree
precondition would be git checkout -- ., which the try-fix skill (principles 6 and 8) and the invocation
constraints both forbid because it would destroy those pre-existing changes.
Consequently .github/.baseline-state.json was never written (verified: Test-Path → False), so the
RevertedFiles edit allow-list does not exist. The skill's Step 2 boundary rule and the invocation's
TARGET/BOUNDARY rule both require reporting Blocked without editing any tracked file in that
situation, because an edit outside a tracked allow-list is not restorable by the restore script and would
corrupt the next sequential attempt. This is an environment/precondition blocker, not a Fail: nothing was
compiled or executed, so it does not match the skill's Fail definitions ("code doesn't compile",
"test command runs, tests fail").
Test executions and results
0 of the 2 permitted executions used. The bounded command was withheld, not run:
pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 -Project Controls -Platform windows \
-IncludeClasses "Microsoft.Maui.DeviceTests.RadioButtonTests,Microsoft.Maui.DeviceTests.WindowTests" \
-IncludeMethods "RadioButtonHandlerShouldNotLeak,MauiWinUIWindowDoesntLeak" -Rebuild
| Test | Result |
|---|---|
Microsoft.Maui.DeviceTests.RadioButtonTests.RadioButtonHandlerShouldNotLeak (primary) |
NOT RUN — blocked |
Microsoft.Maui.DeviceTests.WindowTests.MauiWinUIWindowDoesntLeak (mandatory regression) |
NOT RUN — blocked |
With no fix applied, running it would only re-measure the already-known broken/PR state that the completed
gate recorded, while consuming the bounded budget for zero new information. Gate verification was not
re-run and .../PRAgent/gate/content.md was not created or overwritten.
Self-review
0 findings (reviewer-findings.json = []). The diff is empty, so there is no code to walk against
the Overarching Principles or the routed dimensions (Handler Lifecycle, Windows Platform, Memory/Leaks,
plus the always-active Logic and Correctness / Regression Prevention / Complexity Reduction) of
.github/agents/maui-expert-reviewer.md. An empty array is the correct output rather than invented
findings. The review was performed inline; no reviewer sub-agent was launched.
Restore outcome
Step 9 was executed with exactly pwsh .github/scripts/EstablishBrokenBaseline.ps1 -Restore. Because
Step 2 never created baseline state and no attempt edits were made, the expected and observed completion is
No baseline state found / Restored False — the verified no-state path the skill sanctions. All
pre-existing dirty tracked files and untracked paths were preserved exactly as found; no
git restore/checkout/reset/clean/stash and no file deletion was used at any point.
Artifacts
CustomAgentLogsTmp/PRState/37278/PRAgent/try-fix/attempt-1/: baseline.log, approach.md,
reviewer-findings.json, reviewer-findings.diff, result.txt (Blocked), fix.diff,
test-output.log, analysis.md — all eight present (artifact gate passed).
Candidate 2 — Blocked (baseline precondition; no code change, no test run)
PR #37278 — Try-Fix Candidate 2
Result: Blocked (mandatory baseline precondition failed; no production code was modified and no test was executed)
Approach
Designed approach — "Weak WinRT event bridge for RadioButton" (recorded in try-fix/attempt-2/approach.md; not applied).
The candidate's independent root-cause hypothesis is that the native WinRT Checked/Unchecked event-token/projection bookkeeping retains the handler-targeted delegates after the managed tree becomes unreachable. That strong native-event → delegate → RadioButtonHandler → virtual/layout graph explains why the radio handler, radio platform view, layout handler, and layout platform view can remain alive when the test simply drops its locals without explicitly disconnecting handlers.
The planned implementation, confined to src/Core/src/Handlers/RadioButton/RadioButtonHandler.Windows.cs, was to preserve creation-time native GroupName assignment and native grouping, but route the two native callbacks through a private bridge holding only a WeakReference<RadioButtonHandler>. While the handler is alive, callbacks would forward to the same checked-state synchronization; once it is otherwise unreachable, the event callback could no longer keep it or its virtual/layout graph alive. MauiWinUIWindow.cs would remain unchanged and MauiWinUIWindowDoesntLeak would be regression coverage only.
Explicit comparison with current PR and candidate 1
- Current PR radio mechanism: clears native
RadioButton.GroupNameinDisconnectHandler. The completed gate provedRadioButtonHandlerShouldNotLeakstill fails with that fix. Candidate 2 would not clear, replace, delay, or otherwise moveGroupName; it attacks a separate strong event-delegate edge. - Current PR window mechanism: promotes the local window-message callback to an instance method and unsubscribes
_windowManager.WindowMessageinOnClosedPrivate. Candidate 2 would neither move nor duplicate that unsubscription and would not editMauiWinUIWindow.cs. - Candidate 1 mechanism: designed creation-time avoidance of native group registration and controller-only exclusivity. It was blocked before editing/testing, so its static-group-table hypothesis is not treated as executed evidence. Candidate 2 retains initial native
GroupNameassignment and native exclusivity and instead hypothesizes WinRT event-token retention. Thus both the root-cause hypothesis and mechanism differ.
Files and diff
Production/test files changed: none. The baseline script did not create the required edit allow-list. try-fix/attempt-2/fix.diff is explicitly empty (0 bytes), as is reviewer-findings.diff. No candidate-1 artifact, source file, test expectation, gate artifact, or Mac Catalyst test was touched.
(empty candidate diff — no source changes)Baseline blocker and failure analysis
The mandatory command was run exactly and captured in try-fix/attempt-2/baseline.log:
pwsh .github/scripts/EstablishBrokenBaseline.ps1It rejected the same 55 pre-existing dirty tracked harness files and exited with ERROR: DIRTY WORKING DIRECTORY - Cannot establish baseline. It did not emit Baseline established, and .github/.baseline-state.json remained absent. Therefore no RevertedFiles allow-list existed. The invocation and skill require a Blocked result without tracked edits in this state; bypassing it by clean/reset/stash, changing the baseline script, or editing outside an allow-list was prohibited.
This is a precondition Blocked result, not evidence for or against the weak-event hypothesis. No implementation exists to compile or test.
Exact test results
0 test executions used. The only allowed command was not run because source edits were prohibited after baseline failure:
pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 -Project Controls -Platform windows -IncludeClasses "Microsoft.Maui.DeviceTests.RadioButtonTests,Microsoft.Maui.DeviceTests.WindowTests" -IncludeMethods "RadioButtonHandlerShouldNotLeak,MauiWinUIWindowDoesntLeak" -Rebuild| Test | Exact result |
|---|---|
Microsoft.Maui.DeviceTests.RadioButtonTests.RadioButtonHandlerShouldNotLeak (primary) |
NOT RUN — Blocked before implementation/testing |
Microsoft.Maui.DeviceTests.WindowTests.MauiWinUIWindowDoesntLeak (mandatory regression) |
NOT RUN — Blocked before implementation/testing |
The already-completed gate was not rerun or modified, and the Mac Catalyst test was not targeted.
Expert self-review
0 findings. reviewer-findings.json contains []. The review was performed inline against the Overarching Principles; Handler Mapper/lifecycle, Memory Leak Prevention, and Windows Platform routing; and always-active Logic/Correctness, Regression Prevention, and Complexity Reduction rules. With no candidate source diff, there were no changed lines on which to record findings. No reviewer or child agent was launched.
Restoration outcome
Step 9 ran exactly:
pwsh .github/scripts/EstablishBrokenBaseline.ps1 -RestoreIt completed with No baseline state found / Restored False. This is the expected sanctioned no-state outcome because Step 2 never created state and candidate 2 made no tracked edits. All pre-existing dirty and untracked paths were preserved; no restore/checkout/reset/clean/stash command or file deletion was used.
Artifacts
All eight mandatory files exist in CustomAgentLogsTmp/PRState/37278/PRAgent/try-fix/attempt-2/: baseline.log, approach.md, reviewer-findings.json, reviewer-findings.diff, result.txt (Blocked), fix.diff, test-output.log, and analysis.md. The artifact gate passed.
📝 PR Finalize — Recommended Title & Description
Assessment: ✏️ Recommend updating — the description is already detailed and accurate, but the title retains a non-final [WIP] prefix and can name the two cleanup mechanisms more precisely.
Recommended title
[Windows/Mac Catalyst] Memory: Await CALayer cleanup and release WinUI registrations
Recommended description
### Issue Details
After PR #35487 corrected `AssertionExtensions.WaitForGC`, `MauiCALayerAutosizeToSuperLayerBehavior_DoesNotLeak` began failing on Mac Catalyst for:
- `MauiCALayer`
- `StaticCALayer`
- `StaticCAGradientLayer`
- `StaticCAShapeLayer`
The production layer behavior was not leaking. The test called `UIView.AttachAndRun` without awaiting its returned task, so `WaitForGC` could run before `AttachAndRun` removed the view from the native visual hierarchy in its `finally` block.
The submitted Windows changes also target native lifetime registrations: `MauiWinUIWindow` remained subscribed to `WindowMessageManager.WindowMessage` after closing, and the WinUI `RadioButton` handler retained its generated native `GroupName` during handler teardown.
### Description of Change
- Changed the `InvokeOnMainThreadAsync` callback in `MauiCALayerAutosizeToSuperLayerBehavior_DoesNotLeak` to an asynchronous callback and awaited `view.AttachAndRun(...)` before the GC assertion.
- Converted `MauiWinUIWindow`'s window-message callback from a local function to an instance method and unsubscribed it from `WindowMessageManager.WindowMessage` when the window closes.
- Cleared the WinUI `RadioButton.GroupName` in `RadioButtonHandler.DisconnectHandler`.
- Re-enabled `MauiCALayerAutosizeToSuperLayerBehavior_DoesNotLeak`, `MauiWinUIWindowDoesntLeak`, and `RadioButtonHandlerShouldNotLeak`.
### Validation Status
- Mac Catalyst: the awaited `AttachAndRun` cleanup was tested.
- Windows: `MauiWinUIWindowDoesntLeak` passes in focused validation, but the submitted `RadioButtonHandlerShouldNotLeak` case still fails and requires follow-up before this PR is ready.
### Issues Fixed
Fixes #36614
### Platforms Tested
- [ ] Android
- [x] Windows
- [ ] iOS
- [x] Mac Catalyst
| Before | After |
|---|---|
| **Mac Catalyst**<br><img src="https://github.com/user-attachments/assets/c145e6b2-0823-4e7b-93fa-74c957e701e6" width="600" height="300"> | **Mac Catalyst**<br><img src="https://github.com/user-attachments/assets/af942f05-e9b7-436e-97fa-3b212d133c76" width="600" height="300"> |
🏁 Report — Final Recommendation
⚠️ Final Recommendation: REQUEST CHANGES
Winner: pr-plus-reviewer
The submitted PR cannot be approved because the trusted Gate proves that RadioButtonHandlerShouldNotLeak still fails with the raw fix. The pr-plus-reviewer candidate is the only candidate with an implemented change and passing regression evidence: its exact targeted Windows run completed with both required tests passing.
| Rank | Candidate | Implementation | Regression evidence | Assessment |
|---|---|---|---|---|
| 1 | pr-plus-reviewer |
PR plus one consolidated reviewer patch | Passed: 2/2 (RadioButtonHandlerShouldNotLeak, MauiWinUIWindowDoesntLeak) |
Aligns the RadioButton regression with the explicit recursive teardown contract, restores the generated native group on reconnect, and limits the test to Windows. |
| 2 | pr |
Raw submitted fix | Failed: RadioButtonHandlerShouldNotLeak failed with the fix; window test not run; Mac Catalyst blocked on this host |
Keeps the sound awaited Mac Catalyst cleanup and plausible window-event cleanup, but its RadioButton change is not reached by the re-enabled test. |
| 3 | try-fix-1 |
None; creation-time avoidance was only proposed | Blocked: no tests run | The alternative static-group-registration hypothesis is plausible but has no patch or empirical evidence. |
| 4 | try-fix-2 |
None; weak WinRT event bridge was only proposed | Blocked: no tests run | The event-retention hypothesis is unimplemented and untested, with more lifecycle complexity than the winner. |
Why pr-plus-reviewer wins
The raw test creates the handler graph and immediately asks WaitForGC to collect it, while the production change exists only in DisconnectHandler; the Gate's failure is therefore expected. The winning candidate calls the repository's recursive DisconnectHandlers() API before collection, which invokes the changed cleanup for both the layout and child RadioButton, and it makes the disconnect/reconnect lifecycle symmetric by regenerating the unique native group when needed. Its targeted build and both required Windows regressions pass from the mandated sandbox.
Expert-review disposition
| Finding | Raw PR | Winning candidate |
|---|---|---|
| Re-enabled RadioButton test never reaches the changed cleanup | Blocking; Gate confirms failure | Addressed by explicit recursive disconnect; test passes |
Native GroupName is not restored after reconnect |
Unresolved | Addressed by idempotent restoration in ConnectHandler |
| Test is unintentionally enabled on non-Windows targets | Unverified cross-platform expansion | Addressed by Windows scoping |
OnPlatformMessage may stop before final HWND teardown messages |
Discussion item | Unchanged; remains a documented uncertainty |
Mac Catalyst AttachAndRun cleanup is not awaited |
Addressed in raw PR | Preserved unchanged; not runnable on this Windows host |
Comparative risks and limitations
- The winner proves the explicit teardown contract, not collection of an undisconnected handler graph. This matches the production location of the cleanup but narrows what the regression test promises.
- The candidate was not A/B tested with its revised test against the PR base, so the weak-reference assertion's discrimination is inferred from the native named-group retention mechanism rather than remeasured.
- Mac Catalyst validation remains unavailable on the Windows host.
- Required-check retrieval was unavailable because
ghwas unauthenticated; the supplied trusted Gate is the authoritative PR result and is failed. - The
MauiWinUIWindowunsubscription still occurs atClosed. Whether applications are entitled to laterWM_DESTROY/WM_NCDESTROYnotifications throughWindowsLifecycle.OnPlatformMessageshould be resolved before merge or explicitly accepted.
Required PR change
Apply pr-plus-reviewer/reviewer.patch to the submitted branch. Because the winner differs from the raw PR, the recommendation remains REQUEST CHANGES even though the candidate's focused Windows validation passed.
📱 UI Tests — ViewBaseTests
Detected UI test categories: ViewBaseTests
[!WARNING]
No UI test results were produced for the detected categories. The platform-pool run
returned no results — most often because the PR build failed (see the Gate section) or
the deep UI test stage was skipped. Fix the build/gate issues and push again; the review
re-runs on new commits (a maintainer can also re-run it).
🧭 Next Steps — reviewer changes required
The reviewer-enhanced candidate identified changes that are not yet in the submitted PR.
Why: The reviewer-refined PR is the only implemented candidate that passes both required Windows regression tests. It makes the RadioButton test exercise the cleanup contract and restores the native group identity on reconnect, while the raw PR still fails the trusted Gate and both try-fix alternatives are blocked without patches.
Address the actionable findings in this review before merging.
kubaflo
left a comment
There was a problem hiding this comment.
What's the status of this one? Is it ready for review?
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟢 Approval recommended
The changes are localized to device tests/comments and correctly ensure AttachAndRun cleanup completes before the GC leak assertion.
Pull request overview
This PR fixes a race in a Mac Catalyst/iOS device memory-leak test by ensuring native-view cleanup completes before the GC-based leak assertion runs, and re-enables the previously disabled test.
Changes:
- Updated
MauiCALayerAutosizeToSuperLayerBehavior_DoesNotLeakto use an async main-thread callback andawait view.AttachAndRun(...)beforeWaitForGC. - Removed the
TESTS_FAILS_ON_MACCATALYSTpreprocessor guard so the test is active again (still scoped to#if IOS || MACCATALYST). - Updated Windows-only “fails on Windows” comment links to point at issue
#38055.
File summaries
| File | Description |
|---|---|
| src/Core/tests/DeviceTests/Memory/CALayerAutosizeToSuperLayerBehaviorTests.cs | Awaits AttachAndRun inside an async InvokeOnMainThreadAsync callback and re-enables the test (still iOS/Mac Catalyst only). |
| src/Controls/tests/DeviceTests/Elements/Window/WindowTests.Windows.cs | Updates the issue link in a disabled Windows leak test comment. |
| src/Controls/tests/DeviceTests/Elements/RadioButton/RadioButtonTests.cs | Updates the issue link in a disabled Windows leak test comment. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0
- Review effort level: Lite
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
After PR #35487 corrected
AssertionExtensions.WaitForGC,MauiCALayerAutosizeToSuperLayerBehavior_DoesNotLeakbegan failing on Mac Catalyst for:MauiCALayerStaticCALayerStaticCAGradientLayerStaticCAShapeLayerThe production layer behavior was not leaking. The test called
UIView.AttachAndRunwithout awaiting its returned task, soWaitForGCcould run beforeAttachAndRunremoved the view from the native visual hierarchy in itsfinallyblock.Description of Change
InvokeOnMainThreadAsynccallback inMauiCALayerAutosizeToSuperLayerBehavior_DoesNotLeakto an asynchronous callback and awaitedview.AttachAndRun(...)before the GC assertion.MauiCALayerAutosizeToSuperLayerBehavior_DoesNotLeak.Validation Status
AttachAndRuncleanup was tested.Issues Fixed
Fixes #36614
Platforms Tested