EF reduce usage of memory
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
Memory usage with GC
I have 2 quesitions:
- Am i doing something wrong with DbContext so it doesnt dispose correctly?
- 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