Memory leak on Entity framework during HangfireJobs

Tags: #<Tag:0x00007fc8fbb2cbb0>

our client has implementation of current version of hangfire in .net core 2.1. Client has several type of jobs. Some of them are long (couple of minutes). What client is observing is that, after each cycle od processing couple of hundred or thousand of jobs, memory is increasing. We’ve suggested client switching GC from WorkSpace to Server (before with memory leak there was corresponding CPU leak). After this switch memory is increasing less and cpu went back to normal values.

We’ve done memory dump and we see that most of memory is allocated by Entity framework. It looks like that:

root - Caching.Memory.CacheEntry
Entity framework

Client is creating context in job class and it’s passed through several subclasses and loops. It looks like this may be issue because application has some problems with disposing context. They don’t observe any issues related to disposing (method is executing fine at the end of job). Do you have any experience with such cases? I’m wondering if moving cache creation inside the loop may help here.

Sebastian Krystosik