I have jobs with Quartz library, in this DI I create dbcontext as follows.
services.AddDbContext<X>(opt =>
{
opt.UseSqlServer(
connectionString: hostContext.Configuration.GetConnectionString("x"),
configure => configure.MigrationsAssembly("y.x.y.z")
);
}, ServiceLifetime.Transient);
There are asynchronous processes in the jobs, when I tracked the ram usage, I found that the dbcontext object was not fully cleaned by the garbage collector and the ram usage increased a lot in 3-4 days. I can't use scope or singleton as DbContext lifetime.
What causes this memory leak in transient lifetime?
I will use the using block as a last resort
Is there any other solution to my problem?
Is it ok to force kill the object using dispose in the finaly block?
finally
{
_logService.SystemLog(log);
_context.Dispose();
}