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
22.15k stars 1.74k forks source link

Garbage Collection causes a freeze with Shell. #25382

Open Gekidoku opened 6 days ago

Gekidoku commented 6 days ago

Description

After updating to the latest preview for Visual studio my maui app no longer works as intended on android. it already didnt work on ios for me.

What i see when i have a debugger is attached is that my shell loads in and then I see the app freeze and the console is filled with GC messages. Explicit concurrent mark compact GC freed 224KB AllocSpace bytes, 0(0B) LOS objects, 79% free, 6219KB/30MB, paused 1.455ms,8.847ms total 81.461ms

I think this has to do with shell. As a test i already removed all but one flyoutitems from my shell but to no avail. I also removed my image from my flyout item thinking maybe its due to loading in the image. but to no avail.

I then changed my app so it loads in the first page i have as my flyoutitem as its own page outside of the shell structure. now i dont have the GC feed. So i think its something to do with the Shell itself.

Seeing as i cant exacly share the entire app since it requires access to our backend to properly work ill share the files i think are most relevant. My appshell. https://gist.github.com/Gekidoku/3c3e34201c4f0df59e7362e4a313338d

This is called the old fashioned .net 8 way. the assignment to AppShell is to a static variable so I can peek into it during debugging. Its never used to get the instance of the shell.

 if (Shell.Current == null)
{

        AppShell = new AppShellPlanning() { BackgroundColor = Colors.Black };
        Current.MainPage = App.AppShell;

}

Seeing as my screen doesnt freeze when SplashPage is called on its own i dont think whatever is in there is relevant.

Video demonstrating the issue the WebM and mp4 were too big.

Also for some reason my dotnet-dsrouter android cant use adb from my working directory but when i do it in a console from the same directory i can connect to my phone just fine. so geting GC dumps is a bit of a challenge.

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

9.0.0-rc.2.24503.2

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

Unknown/Other

Affected platforms

Android, iOS

Affected platform versions

No response

Did you find any workaround?

No

Relevant log output

No response

Gekidoku commented 3 days ago

I do have sort of a repro project. However this one shows different behavior. i reference this in another issue here

This one throws the GC spam in the console when you press any item in the flyout. So in essence this test project gets one step further and actually opens the flyoutmenu.

ivanpovazan commented 3 days ago

Hello @Gekidoku,

Regarding:

Version with bug 9.0.0-rc.2.24503.2

Is this a regression from previous behavior? Yes, this used to work in .NET MAUI

Is this a regression from .NET 9.0.0-rc.1 or from .NET 8 ?

Gekidoku commented 3 days ago

From .net 8. Further context: Visual studio is 17.12.0 Preview 3.0 So installed .net sdk Version is 9.0.0-rc.2.24503.2

In my csproject i have it set to .net 8 by way of <TargetFrameworks>net8.0-android;net8.0-ios;</TargetFrameworks>

Now going to try with an older version of maui.controls (8.0.6)

Gekidoku commented 3 days ago

Further testing on my end. The demo repo does work with lower versions of maui.controls.

Now going to try this on my acutal app.

Gekidoku commented 3 days ago

Ok my findings are going to make it difficult. going all the way back to.

<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.6" />

"Fixes" it for my regular app. However with the demo repo i cant reproduce the same behavior. so it might have something to do with something inside my page. Ill share what is inside the page.

Splashpage.cs https://gist.github.com/Gekidoku/5d0143ffc46b5f46abfdd57f9d04a329

DashSelector.cs https://gist.github.com/Gekidoku/c471a3fdbc3ca0ac48521e52023297d4

DashRosterCell.cs https://gist.github.com/Gekidoku/ac0e6664f3345431b16ae8c9111ad850

SplashViewModel.cs https://gist.github.com/Gekidoku/d71e9812aed036b17eff56a1e2c47a04

DashItem.cs https://gist.github.com/Gekidoku/324972b9009f592244c321a6eab9619b