We're seeing memory resources not be released:
With the following code using .NET Core:
class Program
{
static void Main(string[] args)
{
while (true) {
var testRunner = new TestRunner();
testRunner.RunTest();
}
}
}
public class TestRunner {
public void RunTest() {
using (var context = new EasyMwsContext()) {
var result = context.FeedSubmissionEntries.Where(fse => TestPredicate(fse)).ToList();
}
}
public bool TestPredicate(FeedSubmissionEntry e) {
return e.AmazonRegion == AmazonRegion.Europe && e.MerchantId == "1234";
}
}
If I remove the test predicate .Where
I get a straight line as expected, with the predicate the memory will continue to rise indefinitely.
So while I can fix the problem I'd like to understand what is happening?
EDIT:
Altering the line to:
public void RunTest() {
using (var context = new EasyMwsContext()) {
var result = context.FeedSubmissionEntries.ToList();
}
}
So I don't believe this is due to client side evaluation either?
EDIT 2:
Using EF Core 2.1.4
Edit 3:
Added a retention graph, seems to be an issue with EF Core?
I ended up running into the same issue. Once I knew what the problem was I was able to find a bug report for it here in the EntityFrameworkCore repository.
The short summary is that when you include an instance method in an IQueryable
it gets cached, and the methods do not get released even after your context is disposed of.
At this time it doesn't look like much progress has been made towards resolving the issue. I'll be keeping an eye on it, but for now I believe the best options for avoiding the memory leak are:
IQueryable
IQueryable
to a list
with ToList()
before using LINQ methods that contain instance methods (not ideal if you're trying to limit the results of a database query)static
to limit how much memory piles up