dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.99k stars 1.72k forks source link

BindableObjects not getting collected causing memory leak, android #24478

Open GBarbieri-IPS opened 2 weeks ago

GBarbieri-IPS commented 2 weeks ago

Description

I have a pretty large application that we migrated over from xamarin to MAUI. Seems that after navigating through our app x~40 times we end up with a memory leak causing the application to hang. I've collected memory dumps at the time of the crash which I'll post here.

image (1) image (2) image

I can see that MIcrosoft.Maui.Controls.SetterSpecificiityList and BindablePropertyContext seem to be eating up a bunch of our resources as dead objects. I was wondering if there was a way to get these bindings to be cleaned up by the GC as I believe these seem to be the cause of our memory leak? I've tried traversing through the visual tree, removing handlers, setting binding context to null, setting the styles to null, unapplying bindings upon disposal. Can't see to get any progress on resolving this issue.

Steps to Reproduce

  1. Navigating through 5 pages of our app
  2. Navigating back to root
  3. Repeat 22 times
  4. Notice application hangs during OnAppearing or OnPageDisappearing

Link to public reproduction project repository

No response

Version with bug

8.0.21 SR4.1

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No workaround yet.

Relevant log output

No response

github-actions[bot] commented 2 weeks ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

Toomas75 commented 2 weeks ago

I had problems with SetterSpecificiityList when used BindableLayout and loaded itemtemplate in non ui thread.

GBarbieri-IPS commented 2 weeks ago

@Toomas75 Were you seeing similar issues as to what I mentioned? If so how did you get around it? Thanks :)

Toomas75 commented 2 weeks ago

@Toomas75 Were you seeing similar issues as to what I mentioned? If so how did you get around it? Thanks :)

Just checked my history. It wasn't views leaking problem as you experience.