Memory leak in DbContextCache #20

Open
opened 2026-07-20 14:46:34 +02:00 by frederik.engelhardt · 0 comments
UnhandledException: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
  at System.Collections.Generic.Dictionary`2.Resize(Int32 newSize, Boolean forceNewHashCodes)
  at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityReferenceMap.Update(InternalEntityEntry entry, EntityState state, Nullable`1 oldState)
  at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.GetOrCreateEntry(Object entity)
  at Microsoft.EntityFrameworkCore.DbContext.Entry(Object entity)
  at Microsoft.EntityFrameworkCore.Infrastructure.Internal.LazyLoader.Load(Object entity, String navigationName)

The original code was written before release of Entity Framework Core.

Check if there is a call to

context.ChangeTracker.Clear();

Provide a global setting to explicitly disable the context cache.

``` UnhandledException: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. at System.Collections.Generic.Dictionary`2.Resize(Int32 newSize, Boolean forceNewHashCodes) at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityReferenceMap.Update(InternalEntityEntry entry, EntityState state, Nullable`1 oldState) at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.GetOrCreateEntry(Object entity) at Microsoft.EntityFrameworkCore.DbContext.Entry(Object entity) at Microsoft.EntityFrameworkCore.Infrastructure.Internal.LazyLoader.Load(Object entity, String navigationName) ``` The original code was written before release of Entity Framework Core. Check if there is a call to ``` C# context.ChangeTracker.Clear(); ``` Provide a global setting to explicitly disable the context cache.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
equadrat-oss/Framework.Data#20
No description provided.