eShop icon indicating copy to clipboard operation
eShop copied to clipboard

Serious MAUI (ClientApp) memory leak problem

Open DarrenStasiak opened this issue 1 year ago • 3 comments

In recent days our company discovered serious memory leak in MAUI app we are working on i.e. views set as transient don't get disposed of correctly resulting in linear memory growth. Firstly we tried using MAUI wiki page on memory leaks, which yield no concrete results to our problem. Our team decided look up how it is done in eShop demo, and we found same leak here.

In demo we added GC.Collect, destructors to each view (on which we put a breakpoints) and label (under "Adventure Works'" title) that displays current heap size.

Examples below:

Cheap size on startup:

Pasted image 20240710125722

Cheap size after opening and closing BasketView 10 times

Pasted image 20240710125812

On opening and closing BasketView breakpoints weren't triggered single time and heap size kept increasing.

After deleting command from button in BasketView destructor started working.

Pasted image 20240710140645 Pasted image 20240710130458

Questions

Why does it happen, is there some explanation to why MAUI behaves this way? If it is not problem with MAUI, then where lays that issue? Do we need to use some practices that aren't shown in this demo?

DarrenStasiak avatar Jul 10 '24 12:07 DarrenStasiak

Let me ping @jonathanpeppers to see if this with the app or is this with .NET MAUI itself somewhere

jamesmontemagno avatar Jul 18 '24 16:07 jamesmontemagno

@DarrenStasiak can you try the latest service release?

  • https://github.com/dotnet/maui/releases/tag/8.0.70

The past few releases have fixed various memory issues. dotnet/eShop/main already has dependabot updates for this one.

The next question I have, what does {Binding CheckoutCommand} bind to?

It seems like the issue could be similar to:

  • https://github.com/dotnet/maui/issues/16124

Do you have a custom ICommand where CanExecuteChanged is not backed by a "weak event"?

jonathanpeppers avatar Jul 18 '24 16:07 jonathanpeppers

I just updated the packages to 8.0.70 so should be a quick pull to test

jamesmontemagno avatar Jul 18 '24 16:07 jamesmontemagno

Will close out as now on newer versions and working on .NET 9

jamesmontemagno avatar Oct 19 '24 00:10 jamesmontemagno