© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
7 replies
Aleksandr

BackgroundService and dbcontext memory issue

I have a background service to update some objects.
And for about 10 minutes of running the service everything is fine, the application uses about 1 GB of RAM, but after that the memory starts growing to 4+ GB, I checked the largest object and it is Microsoft.EntityFrameworkCore.Query.Internal.BufferedDataReader+BufferedDataRecord
I checked this object, and there is by some objects, why?

here is my code of dbcontext instance and screenshots of the problem, I tried to use the temporary database context, but it doesn’t work, if you run the code through the controller using a timer, then everything is ok, so I suspect dbcontext + ef core

using var scope = _scope.CreateScope();
using var context = scope.ServiceProvider.GetRequiredService<WebApiContext>();
using var scope = _scope.CreateScope();
using var context = scope.ServiceProvider.GetRequiredService<WebApiContext>();
image.png
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Proper way of using EF DbContext in a BackgroundService
C#CC# / help
13mo ago
Dbcontext and SaveChanges()
C#CC# / help
5mo ago
BackgroundService Question
C#CC# / help
11mo ago
❔ Windows BackgroundService
C#CC# / help
3y ago