question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Query: Allow non static methods in top level projection

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:5
  • Comments:22 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
ajcvickerscommented, Aug 21, 2018

@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.

0reactions
rojicommented, Oct 10, 2021

@LucasLopesr see @smitpatel’s comment just above - which version of EF Core are you using?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found