maui: Memory leaks - After running 24 hours it crashes
Description
I have a very simple APP - which shows web pages and images in turn. I am using MS VS Profiler and Objects and Heapisize gradually increases and at the end OOM - Out of Memory happens and the app crashes. I thought it was on my part, I was using Singleton, and I removed all singleton, no help. Second I was using a recursive call, I went to use while(true), but no help. I was using SemaphoreSlim, and removed it, no help. I took all the blame, but none was helping me.
I though it was Grid view, though Grid view causes a faster OOM crash, but removing it also did not help
The profiler does not show anything about my code doing wrong… This app should run all the time on screens, but it’s not usable, I am planning to move from Net MAUI to Native Android Development. I was hoping to get one stone for 4 birds, but I have no bird at all.
I am not sure if anybody will hear my voice… I feel I wasted my months on this app.
Steps to Reproduce
1- Create an app with an Image and Webview on the content page - 2- Then just show images in rotation and websites, Wait ~24 hours on the Android Device will crash, but Windows will survive since there are vast amount of memory 3-Open profiler and observe Objects and Heapisize grow gradually until it can no longer get tolerated by the OS
Link to public reproduction project repository
https://github.com/mgungorchamp/InfoBoard/tree/Semaphore-NoSingletonNoRecursive/InfoBoard
Version with bug
7.0.92
Is this a regression from previous behavior?
No, this is something new, Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Android, Windows
Affected platform versions
All Android
Did you find any workaround?
No workaround
Relevant log output
At the end you will see OOM message and crash.
[cr_ChildProcessConn] onServiceDisconnected (crash or killed by oom): pid=10851 bindings:W S
About this issue
- Original URL
- State: open
- Created 10 months ago
- Reactions: 4
- Comments: 42 (13 by maintainers)
Thank you for your diagnosis. I am not sure what other surprises waiting for me down the road. I spent so much time on this. I am moving to Android Studio and Java. Thanks for the help.
My application crashes after running for about 4 to 5 hours. However, the console app, which uses the same library, works without any issues. I attempted to use .NET 8 to check for memory leaks, but in release mode, it gets stuck on loading. I started a new project from scratch and tried to build it in release mode, but it gets stuck during loading. Later, when I initiated a standard Maui project and installed the SignalR client, it keeps connecting and disconnecting continuously. It seems that SignalR has some issues when operating in release mode on .NET 8. At this point, I’m at a loss and have exhausted all potential solutions. I’ve decided to switch to Java and develop a native application. Unfortunately, this means that my 5 to 6 month-long project has gone to waste.
Yeah, we’ve put most of the memory leak fixes in .NET 8 and not in .NET 7. Before you give up, you might want to test with the latest previews to see if it improves. If it doesn’t, let us know! We’re still working diligently on tracking these down. Thanks!!!
Maybe just to recap where we are on this issue:
I did not observe any memory leaks using dotnet/maui/main. Maybe @mgungorchamp can comment if .NET8 fares any better?
I did see @mgungorchamp’s logs, where the Mono runtime appeared to crash on
arm(32-bit) devices in .NET 7. It feels like it could be a runtime issue.I’m not able to observe the app crashing as @mgungorchamp is. However, the best I have are older Pixel devices that are
arm64.To move further on this, there are two paths @mgungorchamp can take to help us investigate further:
If we had a smaller repro, it would help me investigate any memory leaks (as there should be objects less in memory) – and we would have something the runtime team would have an easier time investigating. Thanks!