I a开发者_开发问答m running a memory profiler on my application to find a possible memory leak. The number of System.Data.Metadata.Edm.TypeUsage objects is consistently growing and it looks like this may be cause of my memory issues.
Does anyone know a way of releasing these TypeUsatge objects from memory? They look to be internal Entity Framework objects since I do not have any reference to them in my code. I have confirmed that I have wrapped the context object within a using block, and the memory is being released, but this Type usage doesn't want to go away.
Any help you can provide would be greatly appreciated.
You are probably looking at the 1st-level cache (Change Tracker) that Entity Framework uses underneath. To read more about it check this out. I'd be surprised if there is a memory leak here, more likely that this is just normal behaviour. How much memory do you see leaking?
To release the memory, try using another merge option (like NoTracking). The default is AppendOnly, which will hold on to types in memory that you might use again. NoTracking merge option will go to the database every time and hold nothing in memory.
Hope this helps.
精彩评论