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

Garbage Collection causes a freeze with Shell. #25382

Open
Gekidoku opened this issue Oct 18, 2024 · 15 comments
Open

Garbage Collection causes a freeze with Shell. #25382

Gekidoku opened this issue Oct 18, 2024 · 15 comments
Assignees
Labels
area-controls-shell Shell Navigation, Routes, Tabs, Flyout platform/android 🤖 platform/iOS 🍎 s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working

Comments

@Gekidoku
Copy link

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 Gekidoku added the t/bug Something isn't working label Oct 18, 2024
@samhouts samhouts added platform/android 🤖 platform/iOS 🍎 potential-regression This issue described a possible regression on a currently supported version., verification pending area-controls-shell Shell Navigation, Routes, Tabs, Flyout labels Oct 18, 2024
@PureWeen PureWeen added this to the .NET 9 Servicing milestone Oct 18, 2024
@Gekidoku
Copy link
Author

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
Copy link
Member

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
Copy link
Author

Gekidoku commented Oct 21, 2024

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
Copy link
Author

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
Copy link
Author

Gekidoku commented Oct 21, 2024

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

@CathyZhu0110 CathyZhu0110 added the s/triaged Issue has been reviewed label Nov 12, 2024
@Gekidoku
Copy link
Author

Wre now almost a month later.
Can someone shed some light on this.

@Gekidoku
Copy link
Author

I see now that the 9.0.0 version is released. going to try this one

@Gekidoku
Copy link
Author

Allright we have progress.
I found the cause.
Hold your horses. its due to a style i have

 <Color x:Key="Primary">#28aadc</Color>
 <Color x:Key="PrimaryDarkText">White</Color>
 <Color x:Key="FlyoutColor">LightBlue</Color>
<Style x:Key="BaseStyle" TargetType="Element">
    <Setter Property="Shell.ForegroundColor" >
        <Setter.Value>
            <OnPlatform x:TypeArguments="Color">
                <On Platform="iOS" Value="White"/>
                <On Platform="Android" Value="Transparent"/>
            </OnPlatform>
        </Setter.Value>
    </Setter>
    <Setter Property="Shell.TitleColor" Value="White" />
    <Setter Property="Shell.DisabledColor" Value="#B4FFFFFF" />
    <Setter Property="Shell.UnselectedColor" Value="Black" />
  
 
    <Setter Property="Shell.FlyoutBackground" Value="{AppThemeBinding Light={StaticResource PrimaryBackground},Dark={StaticResource PrimaryDarkBackground}}"/>
</Style>
<Style TargetType="FlyoutItem" BasedOn="{StaticResource BaseStyle}" />
<Style Class="FlyoutItemLabelStyle" TargetType="Label">
    <Setter Property="TextColor" Value="Black"></Setter>
</Style>
<Style Class="FlyoutItemLayoutStyle" TargetType="Layout" ApplyToDerivedTypes="True">
   
    <Setter Property="VisualStateManager.VisualStateGroups">
        <VisualStateGroupList>
            <VisualStateGroup x:Name="CommonStates">
                <VisualState x:Name="Normal">
                    <VisualState.Setters>
                        <Setter Property="Background" Value="Transparent" />
                        <Setter TargetName="FlyoutItemLabel" Property="Label.TextColor" Value="{StaticResource Primary}" />
                    </VisualState.Setters>
                </VisualState>
                <VisualState x:Name="Selected">
                    <VisualState.Setters>

                        <Setter Property="Background" Value="{StaticResource FlyoutColor}" />
                        <Setter TargetName="FlyoutItemLabel" Property="Label.TextColor" Value="{StaticResource PrimaryDarkText}" />
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateGroupList>
    </Setter>
</Style>

Removing this style causes the app to no longer freeze when setting the app shell as the main page.

@jfversluis
Copy link
Member

Interesting. I understand you can't share your full app, but thats not what a reproduction is about. In order to close in on why a style is making this go wonky it would be super helpful if you could still identify the moving parts and put that in a separate project, that would be super helpful.

But seems this is fixed for you and I think an edge case so if you're not going to I can understand. I'll apply a label asking for a reproduction. If you don't want to just let it expire and it will close this issue for now.

Thanks and great work on finding it eventually!

@jfversluis jfversluis added s/needs-repro Attach a solution or code which reproduces the issue and removed potential-regression This issue described a possible regression on a currently supported version., verification pending labels Nov 13, 2024
@Gekidoku
Copy link
Author

I was able to get somewhat comparable behavior in this project.
https://github.com/Gekidoku/UnfocusTest
Now I didn't push the code to the project yet. I'll do that next morning for me. (Will be in about 13 hours as it's 20:15 here)
The only difference is. Here the app freezes as soon as you click on an item in the flyout.

Again I'll push the version where I could reproduce it tomorrow.

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-repro Attach a solution or code which reproduces the issue labels Nov 13, 2024
@Gekidoku
Copy link
Author

Ok i updated my project
https://github.com/Gekidoku/UnfocusTest

In this project i can reproduce it like this.
In Resources > Styles.xaml i have the style for the flyout.
If you leave this in then the app will freeze when you select an item in the FlyoutMenu.
If you comment it out and then run the app it wont freeze when you select an item in the flyoutmenu.

@Zhanglirong-Winnie
Copy link

Hi, @Gekidoku
We verified this issue on 17.13 Preview 1 using the latest project you provided (9.0.0-rc.2.24503.2 & 9.0.0):
iOS: Can repro on 9.0.0-rc.2.24503.2 & 9.0.0.
Android: Not repro, switching the option does not cause the app to freeze. We found the following information in Output:
Explicit concurrent copying GC freed 25351(1142KB) AllocSpace objects, 6(120KB) LOS objects, 49% free, 6020KB/11MB, paused 488us,70us total 14.129ms

@ivanpovazan
Copy link
Member

Ok i updated my project https://github.com/Gekidoku/UnfocusTest

In this project i can reproduce it like this. In Resources > Styles.xaml i have the style for the flyout. If you leave this in then the app will freeze when you select an item in the FlyoutMenu. If you comment it out and then run the app it wont freeze when you select an item in the flyoutmenu.

@BrzVlad could you take a look ^

@BrzVlad
Copy link
Member

BrzVlad commented Nov 14, 2024

Is there any indication in this issue that the hang is related to the runtime in the first place ?

@Gekidoku
Copy link
Author

Sidenote I have since updated to the full release of 9.0.0 (Visual studio 17.12.0 and 9.0.0 for the maui libraries in my csproj)
Same behavior on the ios side.
android side now works and only shows a single Explicit concurrent mark compact GC freed.
ios still same freezing.

@Zhanglirong-Winnie Zhanglirong-Winnie added the s/verified Verified / Reproducible Issue ready for Engineering Triage label Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-shell Shell Navigation, Routes, Tabs, Flyout platform/android 🤖 platform/iOS 🍎 s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

8 participants