-
Notifications
You must be signed in to change notification settings - Fork 742
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
Critical GREF Accumulation Issue with StaticLayout and String in Uno Platform on Android #18951
Comments
Thanks for the report. This is likely an issue coming from Xamarin, which may be related to dotnet/android#9377 and dotnet/runtime#106410 (comment). You can try adjusting the GC bridge and see if it helps. |
We updated our
This change provided some improvement, as the GC freeze now occurs slightly later compared to our previous configuration:
However, the core issue persists, and the GC still freezes during intensive application usage. Any guidance or additional suggestions for tuning these parameters would be greatly appreciated. And we are on |
Thanks. We'll try to reproduce. |
@NerijusN Could you provide the code that you used to reproduce the issue in standalone app? |
Would like to re-open this ticket due to persistent GREF issues involving the following objects:
While the fix mentioned in PR #18956 addresses Java.Lang.String by implementing limits on the JavaStringCache, the issue with android/text/StaticLayout remains unresolved and contributes significantly to GREF accumulation. ObservationsWe tested the benefits of the workaround provided in PR #18956 by calculating the accumulation of Java.Lang.String objects using the snippet below.
PR #18956 may successfully reduce the count of java/lang/String objects during heavy GC operations, as evidenced by logs showing a manageable count of 509 before the GC loop but I doubt it will be enough. ConcernHowever, the GREF counts for android/text/StaticLayout are far greater—over 30,000 instances. This dwarfs the java/lang/String improvements and suggests that StaticLayout needs a similar approach or another resolution to handle its excessive references effectively.
Given the impact of StaticLayout on GREF counts, further investigation and action are required to address this issue comprehensively. |
We were able to get accurate GREF counts using
It appears that GREFs to UI elements are retained after navigating away from a page. It's not just GREFs to TextBlocks and their StaticLayouts that are accumulating, it's all UI elements (Grids, Borders, etc). We also found that finalizers of Pages (added for testing) or objects referenced by Pages are never called on Android, but are called on Windows. This could mean that GREFs are accumulating because Pages (and their controls) are not garbage collected. Attached is a separate project that tries to reproduce this issue. FinalizeBug.zip Test scenario 1: click "Go to page 1/2" a few times, then click "GC" twice. On Windows trace output contains |
Current behavior
We are experiencing a critical issue in our Android application using Uno Platform (version
4.10.39
). After extended usage, the app enters a loop where the garbage collector (GC) struggles to free memory, and objects accumulate in the GREF table until it exceeds the limit, causing performance degradation and eventual crashes.android/text/StaticLayout
is the primary contributor:Logs indicate 30936+17+273=31226 references.
java/lang/String
is also significant:Logs show 8293+63+83=8439 references.
Both grow steadily under normal app usage and are not released.
Massive GC attempts are logged continuously:
Despite frequent GC, the GREF count continues to grow.
Run an isolated page that updates a
TextBlock
with price changes.The GREF limit is reached within minutes.
Attempts to profile have not provided actionable insights.
Observations suggest
StaticLayout
and String instances are created frequently duringTextBlock.Measure
and layout calculations but are not cleaned up.Impact
This issue significantly impacts the app’s stability and makes it unsustainable for production environments.
Request
Could you provide insights or guidance on addressing this GREF accumulation issue?
Are there known workarounds for managing
StaticLayout
orString
references more effectively in the Uno Platform?Expected behavior
GC works as expected and Android app never experiences ANR because of intense GC calls.
How to reproduce it (as minimally and precisely as possible)
No response
Workaround
No response
Works on UWP/WinUI
None
Environment
Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia, Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia
NuGet package version(s)
CollectionTracking 1.0.0
CollectionTracking.DynamicData 1.0.1
DynamicData 7.1.1
GeneratedSerializers.Json 1.0.0-dev.38
Analytics 3.8.0
FluentValidation.DependencyInjectionExtensions 9.5.4
Microsoft.AppCenter.Analytics 5.0.1
Microsoft.AppCenter.Crashes 5.0.1
Microsoft.Extensions.Hosting 3.1.0
Microsoft.Extensions.Http 8.0.1
Microsoft.Extensions.Localization.Abstractions 3.1.0
Microsoft.Extensions.Logging.Filter 1.1.2
Microsoft.Maui.Essentials 8.0.7
Serilog.Settings.Configuration 8.0.0
Serilog.Extensions.Hosting 8.0.0
Serilog.Sinks.File 5.0.0
System.Diagnostics.DiagnosticSource 8.0.0
Refit 8.0.0
Refit.Newtonsoft.Json 8.0.0
Scrutor 4.2.0
Portable.System.DateTimeOnly 8.0.1
Uno.UniversalImageLoader 1.9.37
Mono.AotProfiler.Android 9.0.0-preview1
Xamarin.Kotlin.StdLib.Jdk8 2.0.21.1
BiometryService 1.1.0
Uno.Fonts.Fluent 2.3.0
Uno.WinUI 4.10.39
Uno.WinUI.RemoteControl 4.10.39
Uno.UI.Adapter.Microsoft.Extensions.Logging 4.10.39
Uno.Microsoft.Xaml.Behaviors.Interactivity.WinUI 2.3.1-uno.2
Uno.Microsoft.Xaml.Behaviors.WinUI.Managed 2.3.1-uno.2
Reactive.Annex.Uno.WinUI 1.0.2
Microsoft.Extensions.Logging.Console 8.0.1
Chinook.BackButtonManager 1.1.4
Chinook.BackButtonManager.Uno.WinUI 1.1.4
Chinook.DataLoader.Uno.WinUI 1.2.0
Chinook.DataLoader.DynamicMvvm 1.2.0
Chinook.DynamicMvvm.Uno.WinUI 1.4.3
Chinook.DynamicMvvm 1.4.3
Chinook.DynamicMvvm.CollectionTracking 1.4.3
Chinook.DynamicMvvm.Reactive 1.4.3
Chinook.DynamicMvvm.FluentValidation 1.4.3
Serilog.Sinks.Xamarin 1.0.0
Uno.CodeGen 2.0.0-dev.10
Uno.Injectable 2.0.0-dev.10
Uno.SourceGenerationTasks 4.2.0
MallardMessageHandlers 1.2.0
Chinook.StackNavigation.Abstractions 2.1.2
Chinook.SectionsNavigation.Uno.WinUI 2.1.2
Chinook.SectionsNavigation.Reactive 2.1.2
MessageDialogService.Uno.WinUI 1.0.2
Uno.Material.WinUI 2.6.1
Uno.Toolkit.WinUI 3.0.4
Uno.Toolkit.WinUI.Material 3.0.4
Nventive.Persistence.Reactive 0.4.0-dev.43
Nventive.Persistence.Uno.WinUI 0.4.0-dev.43
Nventive.View.Uno.WinUI 0.5.0-dev.74
ExtendedSplashScreen.Uno.WinUI 1.0.2
Uno.WinUI.Lottie 4.10.39
Uno.CommunityToolkit.WinUI.DeveloperTools 7.1.100
Uno.CommunityToolkit.WinUI.UI.Controls 7.1.100
Uno.WinUI.Svg 4.10.39
Svg.Skia 2.0.0.2
Affected platforms
Android
IDE
Visual Studio 2022
IDE version
17.11.3
Relevant plugins
No response
Anything else we need to know?
No response
The text was updated successfully, but these errors were encountered: