-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Memoryleak VisualstateManager in ButtonStyle on Android #21389
Comments
speaking of workarounds, just wondering: what if instead of using the style directly on each page, you import a smaller resource dictionary which includes the necessary button style into the page? if that works (ie it doesn't still trigger a memory leak), it'd get rid of multiple copies of the style. |
@MitchBomcanhao |
@jonathanpeppers @StephaneDelcroix thoughts? |
I'll check if this is Android specific or a general issue. VSM or Style might be holding a stronger-than-necessary ref to the Label... |
This app seems like it is working for me on both Windows & Android:
@Larhei did you disable XAML hot reload when testing this? (otherwise it can keep things alive) |
I will retest and get back to you
Gesendet von meinem Windows-10 Gerät.
…________________________________
Von: dotnet-policy-service[bot] ***@***.***>
Gesendet: Tuesday, March 26, 2024 10:13:35 PM
An: dotnet/maui ***@***.***>
Cc: Lars Heinrich ***@***.***>; Mention ***@***.***>
Betreff: Re: [dotnet/maui] Memoryleak VisualstateManager in ButtonStyle on Android (Issue #21389)
Hi @Larhei<https://github.com/Larhei>. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. 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.
—
Reply to this email directly, view it on GitHub<#21389 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ALLM2RLT5VIKMY3HZADCBWDY2HQH7AVCNFSM6AAAAABFDB4P6SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMRRGQ4DINBWGI>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Did a Test in release with dotnet gc-dump. Maybe I am reading this wrong... but I still can see LeakingPage in this dump... And this should not be the case from my understanding. Dump |
Do you see the log messages?
If you push/pop the pages a few times and click GC multiple times? I was just tapping quicly and noticed those messages printed. The file just shows 1 instance: It should grow to several instances if there is an issue. |
Hi @jonathanpeppers, how comes this instance is holding multiple button instances? See latest dump file in the repro? Or how comes no instance of the not leaking page is showing even when navigated to that page? I am confused |
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Microsoft.Maui.Controls.Xaml.UnitTests.Maui21839">
<Button x:Name="button" Text="Click me" Style="{StaticResource buttonStyle}"/>
</ContentPage> Application.Current.Resources.Add("buttonStyle",
new Style(typeof(Button)) {
Setters = {
new Setter { Property = VisualStateManager.VisualStateGroupsProperty, Value = new VisualStateGroupList{
new VisualStateGroup {
Name = "CommonStates",
States = {
new VisualState { Name = "Normal" },
new VisualState { Name = "Pressed" },
new VisualState { Name = "Disabled" }
}
}
} }
}
});
var pagewr = new WeakReference(new Maui21839(useCompiledXaml));
await Task.Delay(10);
GC.Collect();
Assert.IsNull(pagewr.Target, "Page leaked"); I can confirm that it leaks |
@jonathanpeppers and @StephaneDelcroix |
* [C] fix a leak in VSG - fixes #21389 * simplify
Description
When creating an explicite Button Style in Styles.xaml like this.
<Style x:Key="MyButtonStyle" TargetType="Button"> <Setter Property="VisualStateManager.VisualStateGroups"> <VisualStateGroupList> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Normal" /> <VisualState x:Name="Pressed"> </VisualState> <VisualState x:Name="Disabled"> </VisualState> </VisualStateGroup> </VisualStateGroupList> </Setter> </Style>
And referencing it on any ContentenPage like this
<Button x:Name="PART_MyButton" Style="{StaticResource MyButtonStyle}" Text="Welcome to .NET MAUI!" VerticalOptions="Center" HorizontalOptions="Center" />
The ContentPage never get garbage collected on Android.
Steps to Reproduce
Link to public reproduction project repository
https://github.com/Larhei/Maui-Issues/tree/main/VisualStateLeak
Version with bug
8.0.10 SR3
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
No response
Did you find any workaround?
Moving the Style to ContentPage.Resources will stop the leak, but with will force me to copy my styles in multiple locations.
Relevant log output
No response
The text was updated successfully, but these errors were encountered: