efcore icon indicating copy to clipboard operation
efcore copied to clipboard

EF reduce usage of memory

Open endesapt opened this issue 1 year ago • 0 comments

I have an ASP.NET Web API project and I am using some background service where i update my DB and add new data(~20000 rows) every 8 hours But even for the first iteration of queries my app is using 400mb of memory(though in DB data it is only ~25mb) And memory usage keeps increasing after each iteration.

I tried to use GC.Collect() and it caused some effect, but it still consumes 660 mb after 3 calls to DB There are photos of memory profiler( red line states for end of one iteration) Memory usage without GC Without_GC

Memory usage with GC with_GC

I have 2 quesitions:

  1. Am i doing something wrong with DbContext so it doesnt dispose correctly?
  2. If not, how can i decrease memory usage in my application

I created test ASP.NET project that shows my problem EFMemoryTest

Database provider: mysql.entityframeworkcore\8.0.0
Target framework: .NET 8.0 Operating system: Windows 10 IDE: Visual Studio 2022 17.8.4

endesapt avatar Feb 18 '24 16:02 endesapt