We have noticed that our UWP apps have memory leaks. I have investigated it and found out that when navigating to new pages, the memory gets higher and doesn't seem to go down by much even when GC runs.
I have put together a small repro that consists of two pages:
- MainPage
<Page>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="70" />
<RowDefinition />
</Grid.RowDefinitions>
<Button x:Name="navigateButton" Content="Navigate" HorizontalAlignment="Center"
Click="NavigateButton_Click" />
<Frame x:Name="mainFrame" IsNavigationStackEnabled="False"
Padding="10" Grid.Row="1" />
</Grid>
</Page>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void NavigateButton_Click(object sender, RoutedEventArgs e)
{
mainFrame.Navigate(typeof(Page1), null, new Windows.UI.Xaml.Media.Animation.DrillInNavigationTransitionInfo());
}
}
- Page1:
<Page>
<VariableSizedWrapGrid ItemWidth="100" ItemHeight="60">
<Button Padding="20, 10" Content="Hello!"/>
<Button Padding="20, 10" Content="Hello!"/>
<Button Padding="20, 10" Content="Hello!"/>
<Button Padding="20, 10" Content="Hello!"/>
<Button Padding="20, 10" Content="Hello!"/>
<!-- And 25 more buttons here -->
</VariableSizedWrapGrid>
</Page>
public sealed partial class Page1 : Page
{
public Page1()
{
this.InitializeComponent();
}
~Page1()
{
Debug.WriteLine("Page dead :(");
}
}
The full source code is available on GitHub.
And you can see a video of the repro.
I have also tried out setting Frame.IsNavigationStackEnabled to false, it doesn't help.
What am I doing wrong here?