Entity framework uses a lot of memory

后端 未结 4 2320
再見小時候
再見小時候 2021-01-04 05:44

Here is a image from the ANTS memory profiler. It seens that there are a lot of objects hold in memory. How can I find what I am doing wrong?

4条回答
  •  暖寄归人
    2021-01-04 05:59

    I had the same problem in a class which uses dependency injection, so the using() option was not an alternative. My solution was to add DbContextOptions to the constructor and as a private field to the class. Then, you can call

    _db.Dispose();
    _db = new BlockExplorerContext(_dBContextOptions);
    

    at appropriate times. This fixed my problem where I was running out of RAM and the application was killed by the OS.

提交回复
热议问题