-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DbContext from pool contains many InternalEntityEntry instances after clearing change tracker #33354
Comments
This issue is lacking enough information for us to be able to fully understand what is happening. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate. |
What is missing for you in the mentioned code, @ajcvickers ? EDIT: I've added both the model and the config code |
@ajcvickers I've created this repro app: https://github.com/mu88/Repro_EFCore_MemoryUsage After setting up the PostgreSQL database, |
@mu88 I am not able to access that repo. Did you make it public? |
🤦🏻♂️ sry about that, it's public now |
@mu88 Your code never disposes the |
It does in our production code, it was just missing in the repo - I've updated the repro code |
I'm sorry @ajcvickers but I cannot use a preview version on our machines 😕 Can I somehow mitigate the issue? |
@mu88 The best workaround would be to stop using context pooling. |
Thx for your precious time and help, @ajcvickers ! Without context pooling, the memory footprint is much smaller: |
Okay @ajcvickers , here's a screenshot from another memory dump without pooling: As you can see, there are still thousands of And please don't answer the best workaround would be to stop using retries 🤣 |
Is there any news about this, @AndriySvyryd / @ajcvickers ? |
If you take a memory dump after all contexts have been disposed it won't show any abnormalities. Closing, as the original issue is a duplicate of #32652 |
@AndriySvyryd , I'm actually taking the snapshots after the |
I disabled context pooling in your sample and I don't see |
Ask a question
I've implemented a job scheduler that processes many records from our PostgreSQL database every few minutes. Within one of our Grafana dashboards, I noticed that the Gen2 size slowly increases over time and finally reaches a plateau:
So I was wondering what causes Gen2 to become that large and created a memory dump. To my surprise, there are thousands of
InternalEntityEntry
objects which retain more than a million objects from being GCed:To be honest, this comes to my surprise as I'd have expected that
context.ChangeTracker.Clear()
discards those elements after saving them - but maybe I'm misunderstanding something? 🤔So I'd like to know whether
a) that is normal/expected behavior and if yes,
b) why is it that there are so many
InternalEntityEntry
objects ending up in Gen2?Include your code
...and the configuration:
For a full repro case, see this repo: https://github.com/mu88/Repro_EFCore_MemoryUsage
Include stack traces
There are no errors or exceptions.
Include verbose output
Include provider and version information
EF Core version: 7.0
Database provider:
Npgsql.EntityFrameworkCore.PostgreSQL
Target framework: .NET 7.0
Operating system: Alpine Linux
IDE: not relevant as it happens on production
The text was updated successfully, but these errors were encountered: