-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Memory leak in .Net 8 using Entity Framework and Sqllite (.Net Maui Android) #34836
Comments
@SebastianKleu - can this be reproduced if you upgrade EFCore to 8.x? Any particular reason you're choosing to stay with 6.x? |
@SebastianKleu also, the code snippet above doesn't seem like it has anything to do with MAUI. Are you saying the same trouble e.g. in a console program? Can you submit a minimal non-MAUI console program that reproduces this? That would help the investigation process considerably. |
@bengavin - Even if I upgrade to version 8, the memory leak still occurs. |
@SebastianKleu I can take a look, but are you seeing an actual OutOfMemoryException at some point? If not, this is probably the normal behavior of a garbage-collected language - the GC kicks in according to various criteria, e.g. only when memory is tight. I'm not sure why things would have changed between 7 and 8, but it's quite unlikely to be related to EF in any way. You can verify this by using EF 7 from .NET 8 - that would isolate the EF version from the .NET version. |
@roji - It does not matter which EF Core nuget package version I am using (I have tried 6.x.x, 7.x.x. and 8.x.x). All versions seems to not work on Dotnet 8 Android devices due to memory consumption. When using Dotnet Android 7 devices (tested with 6.x.x. and 7.x.x EF Core nuget packages) it seems to work just fine. Viewing the logcat logs, I cannot see anything with regards to OutOfMemoryException, I can just see before 10min the app crashes with logs below: |
If the deciding factor here is the .NET version (6 and 7 are fine, 8 isn't), and the EF version doesn't matter, then this is something you're going to have to take up with the MAUI team - there may have been some sort of change there for .NET 8 which explains this. Keep in mind that increasing memory usage in itself does not indicate a memory leak - the GC decides when to reclaim memory based on its own set of considerations (e.g. when there's little memory left), and it's perfectly fine for memory usage to just keep increasing without getting reclaimed for a long while. I don't question that there's a problem with your app on MAUI - there's indeed a clear error there about failing to allocate. At the same time, if there's a memory leak in EF, it would cause an OutOfMemoryException when running the program (not on MAUI), and as far as I understand that's not the case. If you can trigger and OutOfMemoryException outside of MAUI with a minimal code sample, that's definitely something I'll want to see. |
@roji - I did reach out to the Maui team. |
@SebastianKleu thanks for the issue references and the details.
Note that the logs you pasted above indeed point to an out-of-memory error (on Android). My suggestion here is to try to reproduce the same problem on regular .NET (non-mobile), as a way of trying to isolate the issue - for that, I'd expect a OutOfMemoryException if there's an actual leak somewhere. In other words, if you can produce a vanilla .NET repro - not mobile, just a regular .NET console program - which triggers an OutOfMemoryException, that would be the ideal way to make progress with this issue. It's still very unlikely this has anything to do with EF (since the problem started after switching from .NET 7 to 8), but that's what's needed to narrow down the problem and provide the runtime people with the repro they need. Otherwise, if the issue really is only reproducible on Android, things are trickier - and are probably best investigated in dotnet/runtime#108762. I'll post on that issue, and let's see what comes out of that. |
@roji - Thank you. |
Thanks for confirming @SebastianKleu. I'll go ahead and close this issue for now, as it's quite unlikely this is an actual EF issue. However, based on dotnet/runtime#108762 we can reopen as needed. |
Description
Hi,
We have been running our .Net Maui Android app on .Net 7 for some time now and upgraded to .Net 8.
After the upgrade, we realized that the app crashes after a few hours of use.
I have narrowed down the culprit to EF call on Sqllite. I am able to induce this problem by just reading from a table. See below:
Please see attached zip of test application where you can clearly see the memory rise in .Net 8 and not using .Net 7.
See below memory usage of .Net 7 app after 10 min.

See below memory usage of .Net 8 app after 10 min.

See below test application.
TestMaui.zip
Steps to Reproduce
Link to public reproduction project repository
No response
Version with bug
8.0.91 SR9.1
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
7.0.101
Affected platforms
Android
Affected platform versions
Android 10
Did you find any workaround?
No
Relevant log output
No response
The text was updated successfully, but these errors were encountered: