Memory leak with the Microsoft Dependency Injection job factory
See original GitHub issueDescribe the bug
Quartz.NET appears to leak memory when running jobs with the Microsoft.Extensions.DependencyInjection job factory.
Version used
3.6.3
To Reproduce
https://github.com/danports/MemoryLeakTest
Expected behavior
Memory usage should remain relatively stable; instead, it increases without bound:
Additional context
I’m wondering if Quartz.NET is not properly disposing the service scope created for running jobs - when I review the heap in the debugger, it appears that none of the ApplicationDbContext
instances are freed even though some of the TestJob
instances are.
Issue Analytics
- State:
- Created 2 months ago
- Comments:6
Top Results From Across the Web
EF Core Context is causing memory leak
My software using EF Core in combination with a SQLite database within an ASP.NET Core Web API using dependency injection, has a memory...
Read more >Memory Leaks using Dependency Injection with .NET Core
I inherited a .NET Core application that had a memory leak. I found the source to be the way the application used the...
Read more >8 Ways You can Cause Memory Leaks in .NET
WPF Bindings can actually cause memory leaks. The rule of thumb is to always bind to a DependencyObject or to a INotifyPropertyChanged object....
Read more >Debug a memory leak in .NET Core
A memory leak may happen when your app references objects that it no longer needs to perform the desired task.
Read more >Memory Leak · Issue #125 · quartznet ...
In our case, we are using Custom JobFactory and Simple Injector for creating the instances of jobs and to inject other dependencies.
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 FreeTop 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
Top GitHub Comments
Alright, upon further investigation, this is an issue with neither Quartz.NET nor the Sentry .NET SDK - it’s a known problem with the runtime (https://github.com/mono/mono/issues/19665), which apparently gets triggered through the (indirect) interactions between Quartz.NET and Sentry when a Quartz job fails and Sentry logs the exceptions. I guess I got lucky with the previous scheduling engine I was using because it didn’t trigger this issue, which made me suspect Quartz.NET when it was actually the runtime at fault. Sorry for the false alarm!
When I remove Quartz.NET from the repro project (by cutting out the scheduler and executing the
TestJob
directly), I am unable to reproduce the problem, so I can’t yet rule out an issue with Quartz.NET. Continuing to dig deeper.