Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pages retained in memory when using DynamicResource Grid style #15986

Closed
duffh opened this issue Jul 4, 2023 · 4 comments · Fixed by #16145
Closed

Pages retained in memory when using DynamicResource Grid style #15986

duffh opened this issue Jul 4, 2023 · 4 comments · Fixed by #16145
Labels
area-xaml XAML, CSS, Triggers, Behaviors fixed-in-8.0.0-preview.7.8842 Look for this fix in 8.0.0-preview.7.8842! platform/windows 🪟 t/bug Something isn't working t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf)

Comments

@duffh
Copy link

duffh commented Jul 4, 2023

Description

In a .NET MAUI Shell app running on Windows it looks like pages referencing DynamicResource Grid styles are held in memory after navigating to and then away from the page. This results in an increase in memory over time as pages are opened and closed.

Steps to Reproduce

Setup

  1. Create new Maui app. File -> New Solution -> Maui App
  2. Add the following style to Styles.xaml:
<Style x:Key="GridContainer" TargetType="Grid">
    <Setter Property="Grid.RowDefinitions" Value="Auto,*" />
    <Setter Property="Grid.ColumnDefinitions" Value="*,Auto" />
</Style>
  1. Create two new MAUI ContentPages StyledPage and UnstyledPage
  2. Add a Grid element to both of the newly created pages
    4a. To the StyledPage add:
    <Grid Style="{DynamicResource GridContainer}">
     <Label 
         Grid.Row="0" Grid.ColumnSpan="2"
         Text="This is the first row"
         VerticalOptions="Center" 
         HorizontalOptions="Center" />
     <Label 
         Grid.Row="1" Grid.ColumnSpan="2"
         Text="This is the second row"
         VerticalOptions="Center" 
         HorizontalOptions="Center" />
    </Grid>
    
    4b. To the UnstyledPage add:
    <Grid RowDefinitions="Auto, *" ColumnDefinitions="*, Auto">
     <Label 
         Grid.Row="0" Grid.ColumnSpan="2"
         Text="This is the first row"
         VerticalOptions="Center" 
         HorizontalOptions="Center" />
     <Label
         Grid.Row="1" Grid.ColumnSpan="2"
         Text="This is the second row"
         VerticalOptions="Center" 
         HorizontalOptions="Center" />
    </Grid>
    
  3. Add a Button to the MainPage with a clicked event await Navigation.PushAsync(new StyledPage());
  4. Add a Button to the MainPage with a clicked event await Navigation.PushAsync(new UnstyledPage());
  5. Add a Button to the MainPage with a clicked event GC.Collect();

Testing

  1. Run the app targeting Windows
  2. Navigate to the StyledPage
  3. Click the back button
  4. Click the GC Collect button
  5. Take a snapshot of the memory usage
  6. Navigate to the UnstyledPage
  7. Click the back button
  8. Click the GC Collect button
  9. Take a snapshot of the memory usage
  10. Repeat as many times as necessary

Result: Looking at the memory usage snapshots the number of instances of StyledPage in memory increases with the number of times the page has been opened.

image

image

Expected: The page should no longer exist in memory after navigating away, the number of instances in memory should not increase as the page is repeatedly opened. This works correctly for the UnstyledPage.

Link to public reproduction project repository

https://github.com/duffh/MauiStylesMemoryLeakTestApp

Version with bug

8.0.0-preview.5.8529

Last version that worked well

Unknown/Other

Affected platforms

Windows, I was not able test on other platforms

Affected platform versions

Windows SDK 10.0.19041.0

Did you find any workaround?

No response

Relevant log output

No response

@duffh duffh added the t/bug Something isn't working label Jul 4, 2023
@jsuarezruiz jsuarezruiz added area-xaml XAML, CSS, Triggers, Behaviors legacy-area-perf Startup / Runtime performance labels Jul 4, 2023
@jsuarezruiz
Copy link
Contributor

cc @jonathanpeppers

@jonathanpeppers
Copy link
Member

@duffh does this look like the exact same issue as this one?

#16145

@duffh
Copy link
Author

duffh commented Jul 17, 2023

Looks like the same issue to me, thanks for taking a look!

@jonathanpeppers
Copy link
Member

I wasn't aware of this issue filed -- and I just happened to find the problem in another sample, thanks!

@samhouts samhouts added the fixed-in-8.0.0-preview.7.8842 Look for this fix in 8.0.0-preview.7.8842! label Aug 8, 2023
@samhouts samhouts added this to the .NET 8 milestone Aug 8, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Sep 7, 2023
@Eilon Eilon added t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf) and removed legacy-area-perf Startup / Runtime performance labels May 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-xaml XAML, CSS, Triggers, Behaviors fixed-in-8.0.0-preview.7.8842 Look for this fix in 8.0.0-preview.7.8842! platform/windows 🪟 t/bug Something isn't working t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants