Open
Description
Under a specific condition, disposed context's are not being released with a GC. In production it is rapidly increasing memory usage.
Memory Analysis done with Jetbrains dotMemory.
Attached working project:
ReproduceEFCoreMemoryLeakNonStaticHelperMethods.zip
Sample from attached code:
Console.WriteLine("Take 1st snapshot!");
Console.ReadLine();
for(var i=0; i<10; i++)
using (var context = new TestContextSql())
{
var repo = new Repository(context); // <--- The non static helper will leave 10 instances TestContextSql in memory.
//var repo = new RepositoryStatic(context); // <--- The static helper will leave 1 instances TestContextSql in memory.
var query = repo.GetInt();
var list = query.ToList();
}
Console.WriteLine("Force GC");
GC.Collect();
Console.WriteLine("Take 2nd snapshot");
Console.ReadLine();
public IQueryable<int> GetInt()
{
return _context.TestEntities.Select(t => HashCode(t.DateRange1));
}
private int HashCode(string dateRange1)
{
return dateRange1.GetHashCode();
}
Occurs in:
EF Core 2.0.1
EF Core 2.1.1