-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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 Android) #108762
Comments
Just an update. |
Note dotnet/efcore#34836 which tracks this on the EF side. As the problematic memory behavior appears when upgrading from .NET 7 to 8 - without any EF changes - we're assuming this is a non-EF problem for now... But please let me know if help is needed from the EF side! |
@roji any chance of this being related to that other problem with |
@julealgon #50683 indeed seems like a duplicate of this. However, as with many "GC isn't working" issues that users open, I can't see any evidence of a leak - the complaint is that memory usage is growing, not that there's an actual OutOfMemoryException. So it may very well be that TransactionScopeAsyncFlowOption.Enabled causes increased memory usage, but that by no means implies a leak - the GC may simply not be reclaiming the memory yet (but would as memory usage approaches the limit). This is a point we keep need to explain to users. |
Tagging subscribers to 'arch-android': @vitek-karas, @simonrozsival, @steveisok, @akoeplinger |
Tagging subscribers to this area: @roji, @ajcvickers |
@akoeplinger @jeffschwMSFT who's the right person to look at this? This is currently labeled as System.Data; the repro uses TransactionScope (which is System.Transactions rather than System.Data), but in any case at this point it seems like there's a memory-related issue on android only, which is why this was in the dotnet/android repo. |
@BrzVlad for ideas |
@SebastianKleu @roji Could you quickly port this to a console application? It is fine if it not going to leak, since it would be using CoreCLR, but I could test it with mono and it should be easier to investigate. |
TestMaui.zip Please let me know if there's anything else I can provide to assist with the investigation. |
@SebastianKleu Seems like you uploaded the wrong archive since it doesn't contain the Console project. |
@BrzVlad - Sorry about that. Seems I have reached the size limit of .zip folders for Github. See link with updated test applications here: https://github.com/SebastianKleu/TestMaui |
I've been looking at TransactionScope (and ConditionalWeakTable and finalizers) and have at least a partial explanation. I'll try to write it up later today. |
#50683 contains my notes for ConditionalWeakTable (CWT). I don't understand this code enough to say whether CWT is a complete, partial, or irrelevant explanation for this case. There are two aspects of CWT that may be relevant.
|
@SebastianKleu Note that I haven't been able to reproduce the leak on desktop so this issue would appear to be specific to android. |
@BrzVlad - Yes, during my testing as well, it seems to only happen on Android devices. |
Hi guys, Is there anything we can do in the meantime to get around this problem? We really want to upgrade to the LTS version in .Net 8 but this issue is preventing us from doing so. I would appreciate if there is some workarounds we can implement? |
Hi guys, Any update on this? |
Unfortunately I cannot reproduce this issue. I cloned https://github.com/SebastianKleu/TestMaui. I have |
I am working with @SebastianKleu on the project. We are able to reproduce the issue on an Android 10 device. Android 12 and 13 seems to not have the issue. Running the app on an emulator also does not produce the memory issues. The information for the device we are getting the issue looks as follow: |
Could you run the application with the |
Android framework version
net8.0-android, net9.0-android
Affected platform version
.NET 8 & .NET 9
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
Did you find any workaround?
No
Relevant log output
No response
The text was updated successfully, but these errors were encountered: