I’m executing very simple code in linqpad. And i donnt understand where is my memory after executing. It just take memory and doesnot want to return it back.
var step = 200000;
for (int i = 0; i < 1000; i++)
{
//WordStats is linq2sql entity (dataContext.WordStats)
var keys = WordStats.Skip(step*i).Take(step).ToList();
GC.Collect();
}
The LINQ DataContext caches all read objects in the DataContext, even though you don’t have any references to them yourself. If you query for an object later you get the cached version.
Instead of doing
GC.Collect()you should clear the caches of the LINQ context, here is a blogpost describing how.In short:
In LINQPad you should replace
contextwiththis.