Repository navigation
[leak-test] Add memory-leak coverage for VerticalStackLayout family - #36348
Conversation
…ixes #36337) Adds regression coverage for the layout family flagged by the Daily Memory Leak Hunter in issue #36337: StackLayout, VerticalStackLayout, HorizontalStackLayout and AbsoluteLayout. - DeviceTests: adds [InlineData] entries to the HandlerDoesNotLeak theory in src/Controls/tests/DeviceTests/Memory/MemoryTests.cs so the full handler / platform-view teardown is exercised. These are device-only and are validated for compilation here; they execute on the maui-pr-devicetests pipeline. - Core.UnitTests: adds a runner-runnable managed guard (LayoutMemoryTests.LayoutDoesNotLeakAfterChildRemoved) that verifies a long-lived child does not keep a transient layout alive after it is removed. All four cases pass on main today; the test guards against a future managed regression. This change is test-only; no product code is modified. Generated by the Memory Leak Fixer agentic workflow (Track B). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 36348Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 36348" |
There was a problem hiding this comment.
Pull request overview
Adds missing memory-leak regression coverage for the VerticalStackLayout/stack layout family by extending the existing device-test leak theory and introducing a new managed leak guard in Controls.Core.UnitTests.
Changes:
- Extend
HandlerDoesNotLeakdevice test coverage to includeStackLayout,VerticalStackLayout,HorizontalStackLayout, andAbsoluteLayout. - Add a new
Controls.Core.UnitTeststheory ensuring a long-lived child does not keep a transient layout alive after the child is removed.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Controls/tests/DeviceTests/Memory/MemoryTests.cs | Adds the four missing layout types to the existing HandlerDoesNotLeak [Theory] via new [InlineData] entries. |
| src/Controls/tests/Core.UnitTests/Layouts/LayoutMemoryTests.cs | New managed leak guard test that asserts layouts are collectible after removing a long-lived child. |
MauiBot
left a comment
There was a problem hiding this comment.
AI Review Summary
@github-actions[bot] — new AI review results are available based on this last commit:
e0ea9cf. To request a fresh review after new comments or commits, comment/review rerun.
🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix
Gate: Test Verification (Failure-Only Mode)
Result: ❌ FAILED
This is a test-only change (no fix files detected in the diff), so the gate only verifies that the new/changed tests fail against the merge base — proving they reproduce the bug they target.
Platform: ANDROID
Merge base: 5535b43c
| Test | Type | Outcome |
|---|---|---|
MemoryTests |
DeviceTest | PASS ❌ (should fail) |
LayoutMemoryTests |
UnitTest | PASS ❌ (should fail) |
📋 Pre-Flight — Context & Validation
Issue: #Unknown - unavailable (GitHub CLI authentication missing)
PR: #36348 - Add memory leak coverage for StackLayout family
Platforms Affected: android (test platform requested), all platforms for shared unit-test coverage
Files Changed: 0 implementation, 2 test
Key Findings
- GitHub PR/issue metadata and comments could not be fetched because
ghis unauthenticated in this environment; continued from the checked-outpr-review-36348branch. - Local PR diff adds
LayoutMemoryTests.LayoutDoesNotLeakAfterChildRemovedforStackLayout,VerticalStackLayout,HorizontalStackLayout, andAbsoluteLayout. - Local PR diff also adds those layout types to
MemoryTests.HandlerDoesNotLeak, which is relevant to Android device-test coverage throughControls.DeviceTests. - Gate verification was already completed before this run and failed; this phase did not re-run or overwrite gate output.
Code Review Summary
Verdict: NEEDS_DISCUSSION
Confidence: low
Errors: 0 | Warnings: 0 | Suggestions: 0
Key code review findings:
- ℹ No actionable code-review findings. The PR is test-only and the added coverage is consistent with the stated intent.
- ℹ CI/check status remained undetermined because
gh pr checks --requiredwas unavailable without authentication, so the code-review skill rules cap confidence and prohibit LGTM.
Fix Candidates
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| PR | PR #36348 | Add a new shared core unit test for removed-child layout retention and add stack-layout-family types to the existing handler leak device-test matrix. | ❌ FAILED (Gate pre-run) | src/Controls/tests/Core.UnitTests/Layouts/LayoutMemoryTests.cs, src/Controls/tests/DeviceTests/Memory/MemoryTests.cs |
Original PR; gate output exists separately and was not re-run here. |
🔬 Code Review — Deep Analysis
Code Review — PR #36348
Independent Assessment
What this changes: Adds memory-leak coverage for layout types: a new Core unit test verifies removed children do not retain layouts, and the device memory handler leak matrix now includes StackLayout, VerticalStackLayout, HorizontalStackLayout, and AbsoluteLayout.
Inferred motivation: Fill missing memory-regression coverage for layout teardown/handler collection.
Reconciliation with PR Narrative
Author claims: Adds memory-leak coverage for the stack layout family.
Agreement/disagreement: Agrees with the code. The PR is test-only and matches that claim.
Prior Review Reconciliation
No prior ❌ Error findings found. Queried top-level reviews, inline PR comments, and issue comments. MauiBot had ❌ markers, but they were gate-verification status markers, not unresolved code-review findings.
Blast Radius Assessment
- Runs for all instances: No — tests only.
- Startup impact: No.
- Static/shared state: No.
CI Status
- Required-check result: pending/undetermined.
gh pr checks --requiredwas unavailable due missing auth; public API showed many check runs stillin_progress/queued. - Classification: undetermined.
- Action taken: invoked
azdo-build-investigator;ci-analysiswas unavailable. Confidence capped low; no LGTM.
Findings
No actionable ❌ Error,
Failure-Mode Probing
- Long-lived child retained after removal: Covered by
LayoutMemoryTests.cs:22-37;GC.KeepAlive(sharedChild)keeps the child rooted while asserting the layout collects. - Handler/platform leak for added layout types: Covered through existing
HandlerDoesNotLeakpath inMemoryTests.cs:263-357. - Product blast radius: None; changed code is test-only.
Verdict: NEEDS_DISCUSSION
Confidence: low
Summary: The code changes look sound and I found no actionable code issues. However, CI is still undetermined/pending, so the skill rules prohibit LGTM until required checks complete or failures are classified.
🛠️ Fix — Analysis & Comparison
Fix Candidates
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| 1 | try-fix | Clear AndExpandLayoutManager's synthetic grid after arrange and add a measured StackLayout removed-child regression test. |
2 files | Stronger than PR test: initially failed by exposing measured FillAndExpand cache retention, then passed after internal cache-clear fix. |
|
| 2 | try-fix | Clear GridLayoutManager's cached GridStructure after arrange and add a measured Grid removed-child regression test. |
✅ Unit PASS; Android not applicable locally | 2 files | Different cache-backed layout manager; initially failed by exposing measured grid child retention, then passed after cache clear. |
| 3 | try-fix | Clear LayoutViewGroup.CrossPlatformLayout in Android LayoutHandler.DisconnectHandler. |
1 file | Android-specific lifecycle-retention candidate; could not validate locally because device-test script hung without output. | |
| PR | PR #36348 | Add unmeasured removed-child layout unit test and add stack-layout-family types to existing handler leak matrix. | ❌ FAILED (Gate pre-run) | 2 files | Gate said both tests passed against merge base, so they did not prove the targeted regression. |
Cross-Pollination
| Model | Round | New Ideas? | Details |
|---|---|---|---|
| maui-expert-reviewer | 1 | Yes | Proposed measured StackLayout/AndExpandLayoutManager cache-retention test, reversed ownership device leak test, and navigation teardown leak test. |
| maui-expert-reviewer | 2 | Yes | After try-fix-1, proposed a measured GridLayoutManager cache-retention test that can run as a unit test when Android execution is blocked. |
| maui-expert-reviewer | 3 | Yes | Proposed Android LayoutViewGroup.CrossPlatformLayout lifecycle cleanup for platform-view retention. |
| maui-expert-reviewer | 4 | No | NO NEW IDEAS after reviewing candidates 1-3. |
Exhausted: Yes
Selected Fix: Candidate #2 — best validated alternative. It exposes a measured-parent retention problem that the PR's tests miss and passes the full LayoutMemoryTests unit filter after a small internal cache invalidation. Candidate #1 is also viable for StackLayout/AndExpandLayoutManager; Candidate #3 remains unvalidated because Android execution was blocked.
📝 Recommended PR Title & Description
Assessment: ✏️ Recommend updating — the winning candidate is no longer a test-only VerticalStackLayout-family coverage PR; it includes a product fix for GridLayoutManager measured-child retention.
Recommended title
[Core] GridLayout: Clear measured structure after arrange
Recommended description
## Summary
Fixes #36337
The leak-test-gap investigation found that the original test-only coverage for the `VerticalStackLayout` layout family did not exercise measured/arranged layout retention paths. In particular, a measured `Grid` could retain a removed child through `GridLayoutManager`'s cached `GridStructure` after arrange.
## Root cause
`GridLayoutManager` keeps `_gridStructure` after `ArrangeChildren`. That structure caches the laid-out children, so a long-lived measured layout can keep a removed child alive even after `layout.Remove(child)`.
## What changed
**1. Product fix** — `src/Core/src/Layouts/GridLayoutManager.cs`
Clears `_gridStructure` after arrange once the measured size has been read, breaking the retention chain from the layout manager to removed children.
**2. Regression coverage** — `src/Controls/tests/Core.UnitTests/Layouts/LayoutMemoryTests.cs`
Adds a measured/arranged removed-child leak test that:
- creates a `Grid`;
- adds a `Label`;
- runs `CrossPlatformMeasure` and `CrossPlatformArrange`;
- removes the child;
- verifies the removed child can be collected while the layout remains alive.
**3. Existing device-test matrix coverage** — `src/Controls/tests/DeviceTests/Memory/MemoryTests.cs`
Keeps the additive `HandlerDoesNotLeak` data rows for:
- `typeof(StackLayout)`
- `typeof(VerticalStackLayout)`
- `typeof(HorizontalStackLayout)`
- `typeof(AbsoluteLayout)`
## Validation
- The measured-grid regression test failed before the product fix.
- The measured-grid regression test passed after clearing `_gridStructure`.
- The `LayoutMemoryTests` unit-test filter passed after the fix.
- Android device-test execution was blocked in this environment, so Android-specific lifecycle validation still needs CI/device coverage.
## Scope
- Product change is limited to core `GridLayoutManager` cache lifetime after arrange.
- No public API surface is changed.
- No existing test is muted, skipped, weakened, or deleted.
Fixes #36337
Refs: dotnet/maui#36337
🏁 Report — Final Recommendation
Comparative Candidate Report: PR #36348
Ranking
| Rank | Candidate | Regression result | Assessment |
|---|---|---|---|
| 1 | try-fix-2 |
PASS: targeted unit test failed before product fix, then passed; full LayoutMemoryTests filter passed (5 passed). |
Best validated candidate. It proves a real measured-layout retention path in GridLayoutManager and fixes it with a small cache-clear after arrange. |
| 2 | try-fix-1 |
PASS: targeted unit test failed before product fix, then passed; full LayoutMemoryTests filter passed (5 passed). Android execution was blocked. |
Strong and directly relevant to StackLayout expansion caching, but Android validation was blocked and the fix is narrower than the core grid-manager cache issue selected by STEP 5a. |
| 3 | try-fix-3 |
BLOCKED: Android device-test execution produced no usable result. | Plausible Android lifecycle cleanup, but unvalidated. It must rank below candidates with passing regression evidence. |
| 4 | pr-plus-reviewer |
FAIL/needs product fix: reviewer-applied tests would exercise measured/arranged retention and expose leaks, but the candidate remains test-only. | Better test direction than raw PR, but not a complete passing fix candidate. |
| 5 | pr |
FAIL: gate reported both added tests passed on merge base when they should fail. | The submitted PR adds coverage rows, but they do not prove the targeted leak scenario. |
Candidate Details
pr
The raw PR adds a new managed LayoutDoesNotLeakAfterChildRemoved theory and adds StackLayout, VerticalStackLayout, HorizontalStackLayout, and AbsoluteLayout to MemoryTests.HandlerDoesNotLeak.
It failed the gate because both tests passed on the merge base. The managed test never measures or arranges the layout, and the device test uses the generic whole-tree leak check rather than a removed-child or layout-disconnect scenario.
pr-plus-reviewer
The expert reviewer feedback turns the PR toward measured/arranged removed-child testing and Android lifecycle/removal testing. That is the right direction for coverage, but applying it to the PR as a test-only candidate exposes product retention bugs without fixing them. It is therefore not a mergeable winning candidate.
try-fix-1
This candidate targets StackLayout/AndExpandLayoutManager by clearing the synthetic grid and manager after arrange. Its measured FillAndExpand removed-child test failed before the fix and passed afterward. It is a strong candidate, but Android execution was blocked and the selected STEP 5a evidence preferred the broader core grid-manager cache fix.
try-fix-2
This candidate targets GridLayoutManager by clearing its cached GridStructure after arrange. Its measured-grid removed-child test failed before the product fix and passed afterward, and the full LayoutMemoryTests filter passed. The change is small, addresses a proven measured-layout retention root cause, and has the best validation record among all candidates.
try-fix-3
This candidate clears LayoutViewGroup.CrossPlatformLayout during Android LayoutHandler.DisconnectHandler. The retention chain is plausible, but Android validation was blocked, so it cannot outrank validated candidates.
Winner
Winner: try-fix-2
try-fix-2 is the single best candidate because it includes both a failing-before/passing-after regression test and a minimal product fix for a confirmed measured-layout retention root cause. The raw PR and pr-plus-reviewer rank lower because they do not produce a passing complete fix, and blocked Android-only evidence cannot outrank passing unit regression evidence.
🧭 Next Steps — alternative fix proposed (try-fix-2)
Automated review — alternative fix proposed
The expert-reviewer evaluation compared the PR fix against automatically generated candidates and selected try-fix-2 as the strongest fix.
Why: try-fix-2 won because it reproduced a real measured Grid child-retention leak with a failing unit test, fixed it by clearing GridLayoutManager's cached GridStructure after arrange, and then passed the targeted LayoutMemoryTests filter. The raw PR and pr-plus-reviewer remain test-only/coverage-only candidates that failed or would expose the leak without fixing it.
Please consider applying the candidate diff below (or use it as guidance). Once you push an update, this workflow will re-trigger and re-evaluate.
Candidate diff (try-fix-2)
diff --git a/src/Controls/tests/Core.UnitTests/Layouts/LayoutMemoryTests.cs b/src/Controls/tests/Core.UnitTests/Layouts/LayoutMemoryTests.cs
new file mode 100644
index 0000000..af6ff58
--- /dev/null
+++ b/src/Controls/tests/Core.UnitTests/Layouts/LayoutMemoryTests.cs
@@ -0,0 +1,61 @@
+using System;
+using System.Diagnostics.CodeAnalysis;
+using System.Threading.Tasks;
+using Microsoft.Maui.Graphics;
+using Xunit;
+
+namespace Microsoft.Maui.Controls.Core.UnitTests.Layouts
+{
+ [Category(TestCategory.Memory)]
+ public class LayoutMemoryTests
+ {
+ [Theory]
+ [InlineData(typeof(StackLayout))]
+ [InlineData(typeof(VerticalStackLayout))]
+ [InlineData(typeof(HorizontalStackLayout))]
+ [InlineData(typeof(AbsoluteLayout))]
+ public async Task LayoutDoesNotLeakAfterChildRemoved(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type layoutType)
+ {
+ // A long-lived child (for example a view cached by a view model) must not keep a
+ // transient layout alive once it has been removed from that layout, as happens when a
+ // page is navigated away from and its layout tree is torn down.
+ var sharedChild = new Label();
+
+ WeakReference reference;
+ {
+ var layout = (Layout)Activator.CreateInstance(layoutType);
+ layout.Add(sharedChild);
+ layout.Remove(sharedChild);
+ reference = new(layout);
+ }
+
+ await TestHelpers.Collect();
+
+ Assert.False(await reference.WaitForCollect(), $"{layoutType.Name} should not be alive!");
+
+ // Ensure the shared child isn't collected during the test.
+ GC.KeepAlive(sharedChild);
+ }
+
+ [Fact]
+ public async Task MeasuredGridDoesNotRetainRemovedChild()
+ {
+ var layout = new Grid();
+ var child = new Label();
+
+ layout.Add(child);
+ ((Microsoft.Maui.ILayout)layout).CrossPlatformMeasure(320, 480);
+ ((Microsoft.Maui.ILayout)layout).CrossPlatformArrange(new Rect(0, 0, 320, 480));
+
+ var childReference = new WeakReference(child);
+ layout.Remove(child);
+ child = null;
+
+ await TestHelpers.Collect();
+
+ Assert.False(await childReference.WaitForCollect(), "Grid should not retain removed children after measuring and arranging.");
+ GC.KeepAlive(layout);
+ }
+ }
+}
diff --git a/src/Controls/tests/DeviceTests/Memory/MemoryTests.cs b/src/Controls/tests/DeviceTests/Memory/MemoryTests.cs
index 1c5166f..c39e4e1 100644
--- a/src/Controls/tests/DeviceTests/Memory/MemoryTests.cs
+++ b/src/Controls/tests/DeviceTests/Memory/MemoryTests.cs
@@ -216,6 +216,10 @@ public class MemoryTests : ControlsHandlerTestBase
#pragma warning restore CS0618 // Type or member is obsolete
[InlineData(typeof(GraphicsView))]
[InlineData(typeof(Grid))]
+ [InlineData(typeof(StackLayout))]
+ [InlineData(typeof(VerticalStackLayout))]
+ [InlineData(typeof(HorizontalStackLayout))]
+ [InlineData(typeof(AbsoluteLayout))]
#if TESTS_FAILS_ON_WINDOWS //For more information, see: https://github.com/dotnet/maui/issues/35985
[InlineData(typeof(HybridWebView))]
#endif
diff --git a/src/Core/src/Layouts/GridLayoutManager.cs b/src/Core/src/Layouts/GridLayoutManager.cs
index 42076d6..7431819 100644
--- a/src/Core/src/Layouts/GridLayoutManager.cs
+++ b/src/Core/src/Layouts/GridLayoutManager.cs
@@ -47,6 +47,7 @@ namespace Microsoft.Maui.Layouts
}
var actual = new Size(_gridStructure.MeasuredGridWidth(), _gridStructure.MeasuredGridHeight());
+ _gridStructure = null;
return actual.AdjustForFill(bounds, Grid);
}
…36348) > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! > [!IMPORTANT] > This pull request was generated automatically by the **Memory Leak Fixer** agentic workflow (Track B — add missing regression coverage). It is **test-only**; no product code is modified. ## Summary Fixes #36337 The `[leak-test-gap]` issue #36337 (filed by the Daily Memory Leak Hunter) flagged that the `VerticalStackLayout` layout family had no coverage in the memory-leak suites. This PR adds that coverage so a future regression is caught. ## The gap The `HandlerDoesNotLeak` theory in `src/Controls/tests/DeviceTests/Memory/MemoryTests.cs` exercises handler / platform-view teardown for many controls but did not include the core stack / absolute layouts. There was also no runner-runnable managed leak guard for these layouts in `Controls.Core.UnitTests`. ## What this PR adds **1. Device test coverage** — `src/Controls/tests/DeviceTests/Memory/MemoryTests.cs` Adds four `[InlineData]` entries to the existing `HandlerDoesNotLeak` `[Theory]`: - `typeof(StackLayout)` - `typeof(VerticalStackLayout)` - `typeof(HorizontalStackLayout)` - `typeof(AbsoluteLayout)` No `SetupBuilder` change is required: all four derive from `Layout`, and `handlers.AddHandler<Layout, LayoutHandler>()` is already registered, so handler resolution walks to the nearest registered base. **2. Runner-runnable managed guard** — `src/Controls/tests/Core.UnitTests/Layouts/LayoutMemoryTests.cs` (new) `LayoutDoesNotLeakAfterChildRemoved` (a `[Theory]` over the same four types) verifies that a **long-lived child** does not keep a **transient layout** alive once the child has been removed — the managed teardown path that runs when a page is navigated away from and its layout tree is torn down. It models the existing `GridLayoutTests` leak tests (`WeakReference` + `TestHelpers.Collect()` + `WaitForCollect()`). ## Validation - **Managed guard (`Controls.Core.UnitTests`):** built from source and run on the `net` TFM in this run. All four cases **pass on `main`** — these layouts do not leak today, so the test is a forward regression guard, exactly what a `[leak-test-gap]` fix should be: ``` Passed LayoutDoesNotLeakAfterChildRemoved(layoutType: typeof(StackLayout)) Passed LayoutDoesNotLeakAfterChildRemoved(layoutType: typeof(VerticalStackLayout)) Passed LayoutDoesNotLeakAfterChildRemoved(layoutType: typeof(HorizontalStackLayout)) Passed LayoutDoesNotLeakAfterChildRemoved(layoutType: typeof(AbsoluteLayout)) Total tests: 4 Passed: 4 ``` - **Device tests:** `src/Controls/tests/DeviceTests/**` cannot run on this Linux runner (they require platform workloads). The added `[InlineData]` lines are purely additive, use types already in scope via `using Microsoft.Maui.Controls;` (so they resolve to the modern, non-obsolete layout types), and are validated for structure here. They will execute on the **maui-pr-devicetests** pipeline. ## Scope - Test-only. No product / managed code changed; no public API surface affected. - No existing test is muted, skipped, weakened, or deleted. --- Fixes #36337 Refs: #36337 Target branch: main _Generated by the Memory Leak Fixer agentic workflow (Track B)._ > Generated by [Memory Leak Fixer](https://github.com/dotnet/maui/actions/runs/28679863808) · 2.8K AIC · ⌖ 137.6 AIC · ⊞ 63.4K · [◷](https://github.com/search?q=repo%3Adotnet%2Fmaui+%22gh-aw-workflow-id%3A+leak-fixer%22&type=pullrequests) <!-- gh-aw-agentic-workflow: Memory Leak Fixer, engine: copilot, version: 1.0.60, model: claude-opus-4.8, id: 28679863808, workflow_id: leak-fixer, run: https://github.com/dotnet/maui/actions/runs/28679863808 --> <!-- gh-aw-workflow-id: leak-fixer --> <!-- gh-aw-workflow-call-id: dotnet/maui/leak-fixer --> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…36348) > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! > [!IMPORTANT] > This pull request was generated automatically by the **Memory Leak Fixer** agentic workflow (Track B — add missing regression coverage). It is **test-only**; no product code is modified. ## Summary Fixes #36337 The `[leak-test-gap]` issue #36337 (filed by the Daily Memory Leak Hunter) flagged that the `VerticalStackLayout` layout family had no coverage in the memory-leak suites. This PR adds that coverage so a future regression is caught. ## The gap The `HandlerDoesNotLeak` theory in `src/Controls/tests/DeviceTests/Memory/MemoryTests.cs` exercises handler / platform-view teardown for many controls but did not include the core stack / absolute layouts. There was also no runner-runnable managed leak guard for these layouts in `Controls.Core.UnitTests`. ## What this PR adds **1. Device test coverage** — `src/Controls/tests/DeviceTests/Memory/MemoryTests.cs` Adds four `[InlineData]` entries to the existing `HandlerDoesNotLeak` `[Theory]`: - `typeof(StackLayout)` - `typeof(VerticalStackLayout)` - `typeof(HorizontalStackLayout)` - `typeof(AbsoluteLayout)` No `SetupBuilder` change is required: all four derive from `Layout`, and `handlers.AddHandler<Layout, LayoutHandler>()` is already registered, so handler resolution walks to the nearest registered base. **2. Runner-runnable managed guard** — `src/Controls/tests/Core.UnitTests/Layouts/LayoutMemoryTests.cs` (new) `LayoutDoesNotLeakAfterChildRemoved` (a `[Theory]` over the same four types) verifies that a **long-lived child** does not keep a **transient layout** alive once the child has been removed — the managed teardown path that runs when a page is navigated away from and its layout tree is torn down. It models the existing `GridLayoutTests` leak tests (`WeakReference` + `TestHelpers.Collect()` + `WaitForCollect()`). ## Validation - **Managed guard (`Controls.Core.UnitTests`):** built from source and run on the `net` TFM in this run. All four cases **pass on `main`** — these layouts do not leak today, so the test is a forward regression guard, exactly what a `[leak-test-gap]` fix should be: ``` Passed LayoutDoesNotLeakAfterChildRemoved(layoutType: typeof(StackLayout)) Passed LayoutDoesNotLeakAfterChildRemoved(layoutType: typeof(VerticalStackLayout)) Passed LayoutDoesNotLeakAfterChildRemoved(layoutType: typeof(HorizontalStackLayout)) Passed LayoutDoesNotLeakAfterChildRemoved(layoutType: typeof(AbsoluteLayout)) Total tests: 4 Passed: 4 ``` - **Device tests:** `src/Controls/tests/DeviceTests/**` cannot run on this Linux runner (they require platform workloads). The added `[InlineData]` lines are purely additive, use types already in scope via `using Microsoft.Maui.Controls;` (so they resolve to the modern, non-obsolete layout types), and are validated for structure here. They will execute on the **maui-pr-devicetests** pipeline. ## Scope - Test-only. No product / managed code changed; no public API surface affected. - No existing test is muted, skipped, weakened, or deleted. --- Fixes #36337 Refs: #36337 Target branch: main _Generated by the Memory Leak Fixer agentic workflow (Track B)._ > Generated by [Memory Leak Fixer](https://github.com/dotnet/maui/actions/runs/28679863808) · 2.8K AIC · ⌖ 137.6 AIC · ⊞ 63.4K · [◷](https://github.com/search?q=repo%3Adotnet%2Fmaui+%22gh-aw-workflow-id%3A+leak-fixer%22&type=pullrequests) <!-- gh-aw-agentic-workflow: Memory Leak Fixer, engine: copilot, version: 1.0.60, model: claude-opus-4.8, id: 28679863808, workflow_id: leak-fixer, run: https://github.com/dotnet/maui/actions/runs/28679863808 --> <!-- gh-aw-workflow-id: leak-fixer --> <!-- gh-aw-workflow-call-id: dotnet/maui/leak-fixer --> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…36348) > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! > [!IMPORTANT] > This pull request was generated automatically by the **Memory Leak Fixer** agentic workflow (Track B — add missing regression coverage). It is **test-only**; no product code is modified. ## Summary Fixes #36337 The `[leak-test-gap]` issue #36337 (filed by the Daily Memory Leak Hunter) flagged that the `VerticalStackLayout` layout family had no coverage in the memory-leak suites. This PR adds that coverage so a future regression is caught. ## The gap The `HandlerDoesNotLeak` theory in `src/Controls/tests/DeviceTests/Memory/MemoryTests.cs` exercises handler / platform-view teardown for many controls but did not include the core stack / absolute layouts. There was also no runner-runnable managed leak guard for these layouts in `Controls.Core.UnitTests`. ## What this PR adds **1. Device test coverage** — `src/Controls/tests/DeviceTests/Memory/MemoryTests.cs` Adds four `[InlineData]` entries to the existing `HandlerDoesNotLeak` `[Theory]`: - `typeof(StackLayout)` - `typeof(VerticalStackLayout)` - `typeof(HorizontalStackLayout)` - `typeof(AbsoluteLayout)` No `SetupBuilder` change is required: all four derive from `Layout`, and `handlers.AddHandler<Layout, LayoutHandler>()` is already registered, so handler resolution walks to the nearest registered base. **2. Runner-runnable managed guard** — `src/Controls/tests/Core.UnitTests/Layouts/LayoutMemoryTests.cs` (new) `LayoutDoesNotLeakAfterChildRemoved` (a `[Theory]` over the same four types) verifies that a **long-lived child** does not keep a **transient layout** alive once the child has been removed — the managed teardown path that runs when a page is navigated away from and its layout tree is torn down. It models the existing `GridLayoutTests` leak tests (`WeakReference` + `TestHelpers.Collect()` + `WaitForCollect()`). ## Validation - **Managed guard (`Controls.Core.UnitTests`):** built from source and run on the `net` TFM in this run. All four cases **pass on `main`** — these layouts do not leak today, so the test is a forward regression guard, exactly what a `[leak-test-gap]` fix should be: ``` Passed LayoutDoesNotLeakAfterChildRemoved(layoutType: typeof(StackLayout)) Passed LayoutDoesNotLeakAfterChildRemoved(layoutType: typeof(VerticalStackLayout)) Passed LayoutDoesNotLeakAfterChildRemoved(layoutType: typeof(HorizontalStackLayout)) Passed LayoutDoesNotLeakAfterChildRemoved(layoutType: typeof(AbsoluteLayout)) Total tests: 4 Passed: 4 ``` - **Device tests:** `src/Controls/tests/DeviceTests/**` cannot run on this Linux runner (they require platform workloads). The added `[InlineData]` lines are purely additive, use types already in scope via `using Microsoft.Maui.Controls;` (so they resolve to the modern, non-obsolete layout types), and are validated for structure here. They will execute on the **maui-pr-devicetests** pipeline. ## Scope - Test-only. No product / managed code changed; no public API surface affected. - No existing test is muted, skipped, weakened, or deleted. --- Fixes #36337 Refs: #36337 Target branch: main _Generated by the Memory Leak Fixer agentic workflow (Track B)._ > Generated by [Memory Leak Fixer](https://github.com/dotnet/maui/actions/runs/28679863808) · 2.8K AIC · ⌖ 137.6 AIC · ⊞ 63.4K · [◷](https://github.com/search?q=repo%3Adotnet%2Fmaui+%22gh-aw-workflow-id%3A+leak-fixer%22&type=pullrequests) <!-- gh-aw-agentic-workflow: Memory Leak Fixer, engine: copilot, version: 1.0.60, model: claude-opus-4.8, id: 28679863808, workflow_id: leak-fixer, run: https://github.com/dotnet/maui/actions/runs/28679863808 --> <!-- gh-aw-workflow-id: leak-fixer --> <!-- gh-aw-workflow-call-id: dotnet/maui/leak-fixer --> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…36348) > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! > [!IMPORTANT] > This pull request was generated automatically by the **Memory Leak Fixer** agentic workflow (Track B — add missing regression coverage). It is **test-only**; no product code is modified. ## Summary Fixes #36337 The `[leak-test-gap]` issue #36337 (filed by the Daily Memory Leak Hunter) flagged that the `VerticalStackLayout` layout family had no coverage in the memory-leak suites. This PR adds that coverage so a future regression is caught. ## The gap The `HandlerDoesNotLeak` theory in `src/Controls/tests/DeviceTests/Memory/MemoryTests.cs` exercises handler / platform-view teardown for many controls but did not include the core stack / absolute layouts. There was also no runner-runnable managed leak guard for these layouts in `Controls.Core.UnitTests`. ## What this PR adds **1. Device test coverage** — `src/Controls/tests/DeviceTests/Memory/MemoryTests.cs` Adds four `[InlineData]` entries to the existing `HandlerDoesNotLeak` `[Theory]`: - `typeof(StackLayout)` - `typeof(VerticalStackLayout)` - `typeof(HorizontalStackLayout)` - `typeof(AbsoluteLayout)` No `SetupBuilder` change is required: all four derive from `Layout`, and `handlers.AddHandler<Layout, LayoutHandler>()` is already registered, so handler resolution walks to the nearest registered base. **2. Runner-runnable managed guard** — `src/Controls/tests/Core.UnitTests/Layouts/LayoutMemoryTests.cs` (new) `LayoutDoesNotLeakAfterChildRemoved` (a `[Theory]` over the same four types) verifies that a **long-lived child** does not keep a **transient layout** alive once the child has been removed — the managed teardown path that runs when a page is navigated away from and its layout tree is torn down. It models the existing `GridLayoutTests` leak tests (`WeakReference` + `TestHelpers.Collect()` + `WaitForCollect()`). ## Validation - **Managed guard (`Controls.Core.UnitTests`):** built from source and run on the `net` TFM in this run. All four cases **pass on `main`** — these layouts do not leak today, so the test is a forward regression guard, exactly what a `[leak-test-gap]` fix should be: ``` Passed LayoutDoesNotLeakAfterChildRemoved(layoutType: typeof(StackLayout)) Passed LayoutDoesNotLeakAfterChildRemoved(layoutType: typeof(VerticalStackLayout)) Passed LayoutDoesNotLeakAfterChildRemoved(layoutType: typeof(HorizontalStackLayout)) Passed LayoutDoesNotLeakAfterChildRemoved(layoutType: typeof(AbsoluteLayout)) Total tests: 4 Passed: 4 ``` - **Device tests:** `src/Controls/tests/DeviceTests/**` cannot run on this Linux runner (they require platform workloads). The added `[InlineData]` lines are purely additive, use types already in scope via `using Microsoft.Maui.Controls;` (so they resolve to the modern, non-obsolete layout types), and are validated for structure here. They will execute on the **maui-pr-devicetests** pipeline. ## Scope - Test-only. No product / managed code changed; no public API surface affected. - No existing test is muted, skipped, weakened, or deleted. --- Fixes #36337 Refs: #36337 Target branch: main _Generated by the Memory Leak Fixer agentic workflow (Track B)._ > Generated by [Memory Leak Fixer](https://github.com/dotnet/maui/actions/runs/28679863808) · 2.8K AIC · ⌖ 137.6 AIC · ⊞ 63.4K · [◷](https://github.com/search?q=repo%3Adotnet%2Fmaui+%22gh-aw-workflow-id%3A+leak-fixer%22&type=pullrequests) <!-- gh-aw-agentic-workflow: Memory Leak Fixer, engine: copilot, version: 1.0.60, model: claude-opus-4.8, id: 28679863808, workflow_id: leak-fixer, run: https://github.com/dotnet/maui/actions/runs/28679863808 --> <!-- gh-aw-workflow-id: leak-fixer --> <!-- gh-aw-workflow-call-id: dotnet/maui/leak-fixer --> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…36348) > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! > [!IMPORTANT] > This pull request was generated automatically by the **Memory Leak Fixer** agentic workflow (Track B — add missing regression coverage). It is **test-only**; no product code is modified. ## Summary Fixes #36337 The `[leak-test-gap]` issue #36337 (filed by the Daily Memory Leak Hunter) flagged that the `VerticalStackLayout` layout family had no coverage in the memory-leak suites. This PR adds that coverage so a future regression is caught. ## The gap The `HandlerDoesNotLeak` theory in `src/Controls/tests/DeviceTests/Memory/MemoryTests.cs` exercises handler / platform-view teardown for many controls but did not include the core stack / absolute layouts. There was also no runner-runnable managed leak guard for these layouts in `Controls.Core.UnitTests`. ## What this PR adds **1. Device test coverage** — `src/Controls/tests/DeviceTests/Memory/MemoryTests.cs` Adds four `[InlineData]` entries to the existing `HandlerDoesNotLeak` `[Theory]`: - `typeof(StackLayout)` - `typeof(VerticalStackLayout)` - `typeof(HorizontalStackLayout)` - `typeof(AbsoluteLayout)` No `SetupBuilder` change is required: all four derive from `Layout`, and `handlers.AddHandler<Layout, LayoutHandler>()` is already registered, so handler resolution walks to the nearest registered base. **2. Runner-runnable managed guard** — `src/Controls/tests/Core.UnitTests/Layouts/LayoutMemoryTests.cs` (new) `LayoutDoesNotLeakAfterChildRemoved` (a `[Theory]` over the same four types) verifies that a **long-lived child** does not keep a **transient layout** alive once the child has been removed — the managed teardown path that runs when a page is navigated away from and its layout tree is torn down. It models the existing `GridLayoutTests` leak tests (`WeakReference` + `TestHelpers.Collect()` + `WaitForCollect()`). ## Validation - **Managed guard (`Controls.Core.UnitTests`):** built from source and run on the `net` TFM in this run. All four cases **pass on `main`** — these layouts do not leak today, so the test is a forward regression guard, exactly what a `[leak-test-gap]` fix should be: ``` Passed LayoutDoesNotLeakAfterChildRemoved(layoutType: typeof(StackLayout)) Passed LayoutDoesNotLeakAfterChildRemoved(layoutType: typeof(VerticalStackLayout)) Passed LayoutDoesNotLeakAfterChildRemoved(layoutType: typeof(HorizontalStackLayout)) Passed LayoutDoesNotLeakAfterChildRemoved(layoutType: typeof(AbsoluteLayout)) Total tests: 4 Passed: 4 ``` - **Device tests:** `src/Controls/tests/DeviceTests/**` cannot run on this Linux runner (they require platform workloads). The added `[InlineData]` lines are purely additive, use types already in scope via `using Microsoft.Maui.Controls;` (so they resolve to the modern, non-obsolete layout types), and are validated for structure here. They will execute on the **maui-pr-devicetests** pipeline. ## Scope - Test-only. No product / managed code changed; no public API surface affected. - No existing test is muted, skipped, weakened, or deleted. --- Fixes #36337 Refs: #36337 Target branch: main _Generated by the Memory Leak Fixer agentic workflow (Track B)._ > Generated by [Memory Leak Fixer](https://github.com/dotnet/maui/actions/runs/28679863808) · 2.8K AIC · ⌖ 137.6 AIC · ⊞ 63.4K · [◷](https://github.com/search?q=repo%3Adotnet%2Fmaui+%22gh-aw-workflow-id%3A+leak-fixer%22&type=pullrequests) <!-- gh-aw-agentic-workflow: Memory Leak Fixer, engine: copilot, version: 1.0.60, model: claude-opus-4.8, id: 28679863808, workflow_id: leak-fixer, run: https://github.com/dotnet/maui/actions/runs/28679863808 --> <!-- gh-aw-workflow-id: leak-fixer --> <!-- gh-aw-workflow-call-id: dotnet/maui/leak-fixer --> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
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!
Important
This pull request was generated automatically by the Memory Leak Fixer agentic workflow (Track B — add missing regression coverage). It is test-only; no product code is modified.
Summary
Fixes #36337
The
[leak-test-gap]issue #36337 (filed by the Daily Memory Leak Hunter) flagged that theVerticalStackLayoutlayout family had no coverage in the memory-leak suites. This PR adds that coverage so a future regression is caught.The gap
The
HandlerDoesNotLeaktheory insrc/Controls/tests/DeviceTests/Memory/MemoryTests.csexercises handler / platform-view teardown for many controls but did not include the core stack / absolute layouts. There was also no runner-runnable managed leak guard for these layouts inControls.Core.UnitTests.What this PR adds
1. Device test coverage —
src/Controls/tests/DeviceTests/Memory/MemoryTests.csAdds four
[InlineData]entries to the existingHandlerDoesNotLeak[Theory]:typeof(StackLayout)typeof(VerticalStackLayout)typeof(HorizontalStackLayout)typeof(AbsoluteLayout)No
SetupBuilderchange is required: all four derive fromLayout, andhandlers.AddHandler<Layout, LayoutHandler>()is already registered, so handler resolution walks to the nearest registered base.2. Runner-runnable managed guard —
src/Controls/tests/Core.UnitTests/Layouts/LayoutMemoryTests.cs(new)LayoutDoesNotLeakAfterChildRemoved(a[Theory]over the same four types) verifies that a long-lived child does not keep a transient layout alive once the child has been removed — the managed teardown path that runs when a page is navigated away from and its layout tree is torn down. It models the existingGridLayoutTestsleak tests (WeakReference+TestHelpers.Collect()+WaitForCollect()).Validation
Managed guard (
Controls.Core.UnitTests): built from source and run on thenetTFM in this run. All four cases pass onmain— these layouts do not leak today, so the test is a forward regression guard, exactly what a[leak-test-gap]fix should be:Device tests:
src/Controls/tests/DeviceTests/**cannot run on this Linux runner (they require platform workloads). The added[InlineData]lines are purely additive, use types already in scope viausing Microsoft.Maui.Controls;(so they resolve to the modern, non-obsolete layout types), and are validated for structure here. They will execute on the maui-pr-devicetests pipeline.Scope
Fixes #36337
Refs: #36337
Target branch: main
Generated by the Memory Leak Fixer agentic workflow (Track B).