You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use a function in linq expression, then GC can't collect memory.
Steps to reproduce
publicclassGuessWhatController:ControllerBase{protectedGuessWhatContextcontext;publicActionResultMatchList(){varmatchs=context.Matches.Include(y =>y.MatchBanner).OrderByDescending(x=>x.EndTime);varrecommends=context.Recommends.Include(y =>y.Match);returnnewJsonResult(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}));}publicstringGetImageUrl(int?imageID){return$"api/GuessWhat/ImageShow/{imageID}";}}
It cause that memory keep increasing and CG can't collect, but i change code
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
I use a function in linq expression, then GC can't collect memory.
Steps to reproduce
It cause that memory keep increasing and CG can't collect, but i change code
to this
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
The text was updated successfully, but these errors were encountered: