Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Net Core 2.1.6+EF Core 2.2.0 , memory leak happened #14099

Closed
LMing123 opened this issue Dec 6, 2018 · 3 comments
Closed

.Net Core 2.1.6+EF Core 2.2.0 , memory leak happened #14099

LMing123 opened this issue Dec 6, 2018 · 3 comments

Comments

@LMing123
Copy link

LMing123 commented Dec 6, 2018

I use a function in linq expression, then GC can't collect memory.

Steps to reproduce

    public class GuessWhatController : ControllerBase
    {
        protected GuessWhatContext context;
         public ActionResult MatchList()
        {
            var matchs = context.Matches.Include(y => y.MatchBanner).OrderByDescending(x=>x.EndTime);
            var recommends = context.Recommends.Include(y => y.Match);
            return new JsonResult(matchs.Select(x => new
            {
                id = x.ID,
                x.Title,
                startTime = x.StartTime.ToString("yyyy-MM-dd"),
                endTime = x.EndTime.ToString("yyyy-MM-dd"),
                x.NeedVIP,
                x.MatchDetail,
                x.Price,
                banner =x.MatchBanner.URL==null?GetImageUrl(x.MatchBanner.ID): x.MatchBanner.URL,  //this line have a problem
            }));
        }
        public string GetImageUrl(int? imageID)
        {
            return $"api/GuessWhat/ImageShow/{imageID}";
        }
    }

It cause that memory keep increasing and CG can't collect, but i change code

 banner =x.MatchBanner.URL==null?GetImageUrl(x.MatchBanner.ID): x.MatchBanner.URL,

to this

 banner =x.MatchBanner.URL==null? $"api/GuessWhat/ImageShow/{x.MatchBanner.ID}" : x.MatchBanner.URL,  

the problem is resolved.

Further technical details

EF Core version: 2.2
Database Provider: Pomelo.EntityFrameworkCore.MySql
Operating system: Windows 10 1809 17763.168
IDE: Visual Studio 2017 15.9.3

@crucialize
Copy link

Hey, I've also found a memory leak bug just now!

@smitpatel
Copy link
Contributor

Duplicate of #13048

@smitpatel smitpatel marked this as a duplicate of #13048 Dec 6, 2018
@smitpatel
Copy link
Contributor

The issue here is, in order to perform client eval requested by user, we capture the closure. But closure also contains the DbContext hence memory is leaked. Easy work-around for now would be to use static method which wouldn't capture the instance of repository

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants