ServiceProviderCache keeps initially created IServiceProvider indefinitely #27169
Labels
area-dbcontext
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
regression
Servicing-approved
type-bug
Milestone
The
ServiceProviderCache
uses instances ofIDbContextOptions
as keys for the internalConcurrentDictionary
. A key of typeIDbContextOptions
contains, among other things, the extensionCoreOptionsExtension
which has an_applicationServiceProvider
.After creation and disposal of the first
DbContext
theServiceProviderCache
keeps theIDbContextOptions
incl. the (disposed)IServiceProvider
, which keeps allIDisposable
instances in it. One of the disposables is theDbContext
itself.The result is that the reference
_applicationServiceProvider
prevents GC to reclaim the memory.Repro
Program.cs
csproj file
Provider and version information
EF Core version: 6.0.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system: Windows 10 x64
IDE: Rider 2021.3.2
The text was updated successfully, but these errors were encountered: