Skip to content

[leak-test-gap] VerticalStackLayout has no memory-leak (HandlerDoesNotLeak) test #36337

Closed

Description

@github-actions

🤖 AI-generated coverage-gap report

This issue was generated automatically by the Daily Memory Leak Hunter workflow (dotnet/maui/daily-leak-hunter), Pass B — leak-test coverage-gap scan. Pass B is a purely static analysis: it reads the repo's existing memory-leak tests and the shipping control surface, then proposes ONE concrete missing test. No product or test code was modified, built, or run. A human should validate the proposal before merging.

The gap

VerticalStackLayout — and the rest of the StackBase / AbsoluteLayout family — has no memory-leak test. None of these concrete, shipping layouts is asserted to release its handler / platform view / managed view after being removed from the visual tree:

  • VerticalStackLayout
  • HorizontalStackLayout
  • StackLayout
  • AbsoluteLayout

(FlexLayout has the identical gap but is already tracked separately by this scanner, so it is intentionally excluded here.)

Proof it is untested

Every memory-leak coverage source in the repo was checked:

Source Result
src/Controls/tests/DeviceTests/Memory/MemoryTests.cs — HandlerDoesNotLeak [Theory] (lines 199–250) Absent. The InlineData set covers Grid, ContentView, ScrollView, Border, CollectionView, etc. — but no VerticalStackLayout / HorizontalStackLayout / StackLayout / AbsoluteLayout.
Same file — PagesDoNotLeak, CollectionViewHeaderFooterDoesntLeak, GestureDoesNotLeak, Cells Do Not Leak, BindableLayoutDoesNotLeak, WindowDoesNotLeak Absent as a leak subject. The stack layouts appear only as containers / content inside other tests (e.g. MemoryTests.cs:366-367 CV Header/Footer, :549 the BindableLayout container, :566 a DataTemplate root) — never as the object whose collection is asserted.
src/Controls/tests/DeviceTests/Elements/Layout/LayoutTests.cs Only arrange/measure tests (LayoutAlignment theories at :160-162); no WeakReference / GC assertions.
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/MemoryTests.cs (Appium) Covers only DatePicker, WebView, Image. No layouts.

So the stack / absolute layout family is genuinely uncovered.

Why it matters

VerticalStackLayout is the default layout in the .NET MAUI project templates and one of the most-instantiated views in real apps; HorizontalStackLayout, StackLayout, and AbsoluteLayout are close behind. A leak in any of them would affect nearly every page of a typical app.

Layouts are prime leak suspects because they sit at the center of a managed↔native retention triangle: a Layout strongly holds its children in a readonly List<IView> _children (src/Controls/src/Core/Layout/Layout.cs:39), each child is wired to a platform view, and the LayoutHandler bridges the managed layout to the platform container. If any subscription along that path is non-weak, the entire subtree (layout → children → their handlers / platform views) stays rooted after navigation-away. HandlerDoesNotLeak is precisely the test that catches this — it asserts the view, its handler, and its platform view are all collected after removal — yet it never exercises a stack or absolute layout.

Proposed test (copy-paste-ready)

Add the layout family to the existing HandlerDoesNotLeak [Theory] in src/Controls/tests/DeviceTests/Memory/MemoryTests.cs (immediately after the existing Grid entry on line 215):

[InlineData(typeof(Grid))]
[InlineData(typeof(StackLayout))]
[InlineData(typeof(VerticalStackLayout))]
[InlineData(typeof(HorizontalStackLayout))]
[InlineData(typeof(AbsoluteLayout))]

No SetupBuilder change is required. All four derive from Layout, and SetupBuilder already registers the base handler:

handlers.AddHandler<Layout, LayoutHandler>(); // MemoryTests.cs:59

MAUI handler resolution walks up to the nearest registered base, so VerticalStackLayout / AbsoluteLayout / etc. all resolve to LayoutHandler. The existing test body already handles a plain layout view (it wraps the instance in a Grid, builds the tree via CreateHandler<LayoutHandler>, then asserts viewReference / handlerReference / platformViewReference are collected) — no other change is needed.

If you prefer to keep the change tightly scoped, the single highest-value line is:

[InlineData(typeof(VerticalStackLayout))]

Where it runs

This test executes on the AzDO/Helix device-test pipeline (maui-pr-devicetests) across Android / iOS / MacCatalyst / Windows — not on gh-aw. This scan is static; the proposed InlineData is what runs on a device once added.

Scope note

This is a true coverage hole, not an intentional exclusion: sibling layouts Grid and ContentView are already in the theory, and there is no comment or [ActiveIssue] marking the stack layouts as deliberately skipped (unlike CollectionView2, which is commented out pending #29619). Adding them is low-risk — it reuses the existing theory, body, and handler registration, and simply closes the gap so that a future non-weak subscription in the layout path cannot ship untested.


Filed automatically by the Daily Memory Leak Hunter (Pass B — leak-test coverage-gap scan). At most one issue is filed per run; Pass A found no new, distinct, empirically-confirmable managed leak this run, so the run fell through to Pass B.

Generated by Daily Memory Leak Hunter · 469.2 AIC · ⌖ 40.3 AIC · ⊞ 13.9K · ◷

Activity

  1. added a commit that references this issue on Jul 3, 2026
    cb72441
  2. added a commit that references this issue on Jul 16, 2026
    17fd2c4
  3. added this to the .NET 10 SR10 milestone on Jul 16, 2026
  4. added 3 commits that reference this issue on Jul 22, 2026
    8bfa426
    4e4c3e5
    1b60279
  5. added 2 commits that reference this issue on Aug 7, 2026
    ad088ce
    0a73f3f
  6. added 12 commits that reference this issue on Aug 27, 2026
    d90e0a4
    f8a52cd
    92b3f29
    17ef5d9
    801f1ae
    a488915
    8061fb4
    69f2631
    4628ce1
    0e9fdfa
    7c7487a
    06703a5
  7. locked and limited conversation to collaborators on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions