Skip to content

Shell.Items.Clear() does not disconnect handlers correctly #34898

Description

@Vetle444

Description

When clearing Shell.Current.Items and navigating to a new root page:

  • iOS: The page's handler is disconnected, but the handlers on child elements (Label, Entry, Button, etc.) within that page are not disconnected. This means native platform views remain allocated and are never cleaned up, causing a memory/resource leak.
  • Android: Neither the page's handler nor the handlers on child elements are disconnected, causing both the native Android views and the managed page object tree to leak.

Image

Steps to Reproduce

  1. Create a Shell app with a root page containing child elements (Label, Entry, etc.)
  2. Clear Shell.Current.Items, add a new TabBar with a different root page, and navigate to it:
var tabBar = new TabBar { Route = "root1" };
tabBar.Items.Add(new Tab
{
    Items =
    {
        new ShellContent
        {
            ContentTemplate = new DataTemplate(() => new SecondRootPage())
        }
    }
});

Shell.Current.Items.Clear();
Shell.Current.Items.Add(tabBar);
await Shell.Current.GoToAsync("//root1", true);
  1. Check the Handler property on the child elements of the original page and the page handler.

Link to public reproduction project repository

https://github.com/Vetle444/MauiTestApp/tree/shellItemsClearHandlerLeak

Version with bug

10.0.50

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

No response

Affected platforms

iOS, Android

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-shellShell Navigation, Routes, Tabs, Flyoutplatform/androidplatform/ioss/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions