Entity Framework TypeUsage

I run a memory profiler in my application to find a possible memory leak. The number of System.Data.Metadata.Edm.TypeUsage objects is constantly growing, and it looks like this could be causing my memory problems.

Does anyone know a way to free these TypeUsatge objects from memory? They look like internal Entity Framework objects, since I don't have a link to them in my code. I confirmed that I wrapped the context object in the use block, and the memory is freed, but this type use does not want to leave.

Any help you can provide would be greatly appreciated.

+6
source share
1 answer

You are probably viewing a Level 1 cache (Change Tracker) that uses the Entity Framework below it. To learn more about this, check this out. I would be surprised if there would be a memory leak, it is more likely that this is just normal behavior. How much memory do you see a leak?

To free up memory, try using a different merge option (for example, NoTracking). AppendOnly is used by default, which will be used for types in memory that you can use again. The NoTracking merge option will go to the database every time and not store anything in memory.

Hope this helps.

0
source

Source: https://habr.com/ru/post/898165/


All Articles