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

Page weak reference is still alive after pushing and popping pages modally or normally #21143

Closed
MDThomsen opened this issue Mar 12, 2024 · 7 comments
Labels
area-controls-pages Page types memory-leak 💦 Memory usage grows / objects live forever (sub: perf) platform/android 🤖 s/try-latest-version Please try to reproduce the potential issue on the latest public version t/bug Something isn't working t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf)

Comments

@MDThomsen
Copy link

Description

Taking inspiration from this guide from Jonathan Peppers I wanted to investigate why I am experiencing memory increases over time when pushing and popping pages both modally and normally.

I am setting up a weak reference to the page that I am pushing, and then popping. After popping I am performing a GC.Collect(), but I notice that the weak reference is still alive afterwards. I would assume that the weak reference would no longer be alive after popping the page from the view hierarchy.

Code sample:

WeakReference pageReference;

{
     var page = new MainPage("New Modal");
     pageReference = new WeakReference(page);

     await Navigation.PushModalAsync(page);
     await Navigation.PopModalAsync();
}

await Task.Yield();
GC.Collect();
GC.WaitForPendingFinalizers();

Console.WriteLine($"Page still alive: {pageReference?.IsAlive}");

Otherwise please check out the linked sample repo.

Steps to Reproduce

  1. Create a weak reference to a page and push it normally or modally within it's own scope.
  2. Pop the page
  3. Call Garbage Collector
  4. Check if the weak reference is still alive. (It is)

Link to public reproduction project repository

https://github.com/MDThomsen/Weak-Reference-MAUI-Sample/

Version with bug

8.0.6 SR1

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 14

Did you find any workaround?

No response

Relevant log output

No response

@MDThomsen MDThomsen added the t/bug Something isn't working label Mar 12, 2024
@jsuarezruiz jsuarezruiz added legacy-area-perf Startup / Runtime performance area-controls-pages Page types labels Mar 12, 2024
@dalux-era
Copy link

We encountered a similar issue. Seeing a lot of memory leaks, especially using NavigationPage

@mattleibow mattleibow added the memory-leak 💦 Memory usage grows / objects live forever (sub: perf) label Mar 12, 2024
@mattleibow
Copy link
Member

@jonathanpeppers thoughts?

@jonathanpeppers
Copy link
Member

@MDThomsen
Copy link
Author

MDThomsen commented Mar 13, 2024

@jonathanpeppers Here is the attached gcdump, where the ContentPage is getting pushed and popped ten times in a row.
20240313_084013_42800.zip

Yeah, I forgot to make some more concise names for the pages. The MainPage, set in the App.xaml.cs, is a TabbedPage which has one child, which is a ContentPage, that pushes and pops a copy of itself.

@PureWeen PureWeen added this to the Backlog milestone Mar 13, 2024
@jonathanpeppers
Copy link
Member

@MDThomsen can you try the latest "nightly build"?

8.0.20-nightly.10336, for example has a fix for TabbedPage on Android: 2317119

@jonathanpeppers jonathanpeppers added the s/try-latest-version Please try to reproduce the potential issue on the latest public version label Mar 19, 2024
Copy link
Contributor

Hi @MDThomsen. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@dotnet-policy-service dotnet-policy-service bot removed this from the Backlog milestone Mar 30, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 1, 2024
@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-controls-pages Page types memory-leak 💦 Memory usage grows / objects live forever (sub: perf) platform/android 🤖 s/try-latest-version Please try to reproduce the potential issue on the latest public version 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

No branches or pull requests

8 participants