Query: Allow non static methods in top level projection
See original GitHub issueUnder 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
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:22 (14 by maintainers)
Top Results From Across the Web
Non-Static method requires a target? - linq
I was getting this error as well when using a variable returned from a linq query (my query pulled back one object). That...
Read more >Only top-level class methods can be declared static
An Inner class cannot have a static method. You must refactor the inner class to its own class.
Read more >Difference between static and non-static method in Java
A static method is a method that belongs to a class, but it does not belong to an instance of that class and...
Read more >Optimising Entity Framework Core Queries using Projection
It looks sensible enough — it's doing a TOP(1) to get the first row it finds, and it's using a parameter to specify...
Read more >Spring Data JDBC - Reference Documentation
We provide a “template” as a high-level abstraction for storing and querying aggregates. This document is the reference guide for Spring Data JDBC...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ksmithRenweb Sorry, I should have said that we know what the issue is. Deciding what to do about it is a different matter–it plays into #12795 because behavior is a consequence of how we evaluate the opaque method call on the client. We’re considering changing some of this in 3.0.
@LucasLopesr see @smitpatel’s comment just above - which version of EF Core are you using?