-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
area-controls-titleviewTitleViewTitleViewarea-navigationNavigationPageNavigationPagep/2Work that is important, but is currently not scheduled for releaseWork that is important, but is currently not scheduled for releasepartner/syncfusionIssues / PR's with Syncfusion collaborationIssues / PR's with Syncfusion collaborationperf/memory-leak 💦Memory usage grows / objects live forever (sub: perf)Memory usage grows / objects live forever (sub: perf)platform/ioss/triagedIssue has been reviewedIssue has been reviewedt/bugSomething isn't workingSomething isn't working
Milestone
Description
Description
It seems if I add NavigationPage.TitleView into a ContentPage's XAML, the page will never be destroyed if it's popped from the navigation stack with PopToRootAsync, leading to an accumulation of pages in memory. It is destroyed if I use PopAsync instead. It is also destroyed with PopToRootAsync if I remove the NavigationPage.TitleView.
Steps to Reproduce
- Create a new Maui app project in Visual Studio (.NET 9)
- Modify
App.xaml.cs,MainPage.xaml.cs, andMainPage.xamlwith the below snippets - Start the app in an iOS simulator (mine is iPhone 15 iOS 18.1). If you click Push, Pop, Push, Pop, etc. you will notice that after 10-20 repetitions "Destroyed" is logged to the console (as many as the number of unloaded pages), indicating that the pages were destroyed.
- Restart the app. If you click Push, Pop To Root, Push, Pop To Root, etc. you will not see "Destroyed" even after many repetitions. (unless you accidentally clicked Pop)
- (optional) Remove the
NavigationPage.TitleView, and if you repeat step 4 you will see that now "Destroyed" is being logged.
MainPage.xaml (and replace MauiApp7 in x:Class with your project name)
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiApp7.MainPage">
<NavigationPage.TitleView>
<Label>Test</Label>
</NavigationPage.TitleView>
<ScrollView>
<VerticalStackLayout
Padding="30,0"
Spacing="25">
<Image
Source="dotnet_bot.png"
HeightRequest="185"
Aspect="AspectFit"
SemanticProperties.Description="dot net bot in a hovercraft number nine" />
<Label
Text="Hello, World!"
Style="{StaticResource Headline}"
SemanticProperties.HeadingLevel="Level1" />
<Label
Text="Welcome to .NET Multi-platform App UI"
Style="{StaticResource SubHeadline}"
SemanticProperties.HeadingLevel="Level2"
SemanticProperties.Description="Welcome to dot net Multi platform App U I" />
<Button
x:Name="PushBtn"
Text="Push"
Clicked="OnPushClicked"
HorizontalOptions="Fill" />
<Button
x:Name="PopBtn"
Text="Pop"
Clicked="OnPopClicked"
HorizontalOptions="Fill" />
<Button
x:Name="PopToRootBtn"
Text="Pop To Root"
Clicked="OnPopToRootClicked"
HorizontalOptions="Fill" />
</VerticalStackLayout>
</ScrollView>
</ContentPage>MainPage.xaml.cs
public partial class MainPage : ContentPage
{
public MainPage()
{
Console.WriteLine("Created");
InitializeComponent();
}
~MainPage()
{
Console.WriteLine("Destroyed");
}
private void OnPushClicked(object sender, EventArgs e)
{
Navigation.PushAsync(new MainPage(), true);
}
private void OnPopClicked(object sender, EventArgs e)
{
if (Navigation.NavigationStack.Count > 0)
Navigation.PopAsync(true);
}
private void OnPopToRootClicked(object sender, EventArgs e)
{
Navigation.PopToRootAsync(true);
}
}App.xaml.cs
public partial class App : Application
{
public App()
{
InitializeComponent();
}
protected override Window CreateWindow(IActivationState? activationState)
{
return new Window(new NavigationPage(new MainPage()));
}
}Link to public reproduction project repository
No response
Version with bug
9.0.40 SR4
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
iOS, I was not able test on other platforms
Affected platform versions
iOS 18.1
Did you find any workaround?
Use PopAsync instead
Relevant log output
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-controls-titleviewTitleViewTitleViewarea-navigationNavigationPageNavigationPagep/2Work that is important, but is currently not scheduled for releaseWork that is important, but is currently not scheduled for releasepartner/syncfusionIssues / PR's with Syncfusion collaborationIssues / PR's with Syncfusion collaborationperf/memory-leak 💦Memory usage grows / objects live forever (sub: perf)Memory usage grows / objects live forever (sub: perf)platform/ioss/triagedIssue has been reviewedIssue has been reviewedt/bugSomething isn't workingSomething isn't working