Comments (5)
Hello @schuettecarsten ,
The IncludeOptimized
feature uses the QueryFuture
to execute his queries.
We can see that a ConditionalWeakTable
is used on this line: https://github.com/zzzprojects/EntityFramework-Plus/blob/master/src/shared/Z.EF.Plus.QueryFuture.Shared/QueryFutureManager.cs#L61C35-L61C139
So, if the context is never disposed of, the QueryFutureBatch
related will never be disposed of either and will just continue to grow. That could probably explain the current behavior with the PooledDbContextFactory
. However the Queries
are cleared
once executed, so it doesn't totally explain why it grows by 60
to 80
MB every run.
Is it possible for you to try in a development environment and see if the same behavior happens with SaveChanges
? If that's the case, that will give us a big hint that the troublemaker is probably the IncludeOptimized
method.
Best Regards,
Jon
from entityframework-extensions.
Hi @JonathanMagnan,
thank you for the explanation. I have done some tests and the memory leaks go away when I switch from PooledDbContextFactory
to DbContextFactory
. Using SaveChanges
instead of BulkSaveChanges
has no effect. I cannot use the standard Include
because this will break the software due to excessive memory consumption.
Do not trust the 60 to 80 megabytes value, it's just what I could estimate from task manager while observing the software. I took a memory dump and analyzed it using Jetbrains dotMemory and could see lots of entities held by the DbContext
instances that were stored in the pool.
from entityframework-extensions.
Hello @schuettecarsten ,
Thank you for the info, so there is a huge chance that the memory leak is due to the ConditionalWeakTable
as the DbContext
is never really released.
We will continue to look at it, but you might have a few options you might want to try.
Clearing the cache
Using QueryFutureManager.CacheWeakFutureBatch.Clear();
to clear the ConditionalWeakTable
(if you can) from time to time. To free some memory if we indeed have a memory leak on that feature.
Using IncludeGraph with the most recent version
It will not fix this issue and will require you to use method such as BulkMerge
, but I find it worth mentioning as our new IncludeGraph
dramatically decreases the memory usage: https://entityframework-extensions.net/v7-100-0-0-include-graph#memory-performance-improvements
If you test the Clear
on the ConditionalWeakTable
, let us know if that fixed the memory leak
from entityframework-extensions.
@JonathanMagnan
During my tests I found an issue with BulkSaveChangesAsync
, when trying to set IncludeGraph
to true, I get the exception Oops! You cannot use the IncludeGraph option with LegacyIncludeGraph. Use one or the other but not both
, but I did not touch LegacyIncludeGraph
at all, only IncludeGraph
to true. Setting LegacyIncludeGraph
to false did not help.
from entityframework-extensions.
@JonathanMagnan
Calling QueryFutureManager.CacheWeakFutureBatch.Clear()
from time to time does not fix the memory issue, unfortunately.
from entityframework-extensions.
Related Issues (20)
- Invalid Cast. The update expression must be of type MemberInitExpression. HOT 3
- Bulk Operations for Postgres does not respect the PermanentTable setting HOT 2
- Avoid Prepared Statements for Bulk operations HOT 6
- WhereBulkContains throwing System.ArgumentNullException: 'Value cannot be null. (Parameter 'name')' HOT 15
- BulkUpdate and BulkMerge Do Not Apply Any Changes To The Table with Owned Entity HOT 1
- BulkSaveChanges results in Foreign Key Constraint Violation but SaveChanges works HOT 3
- BulkMerge is Causing Violation of PRIMARY KEY constraint HOT 1
- BulkInsert: System.IndexOutOfRangeException: 'There is no row at position 0.' HOT 4
- While inserting new record through BulkMerge it's not overriding default constraint value HOT 3
- The type initializer for 'Z.BulkOperations.LicenseManager' threw an exception HOT 13
- `PublicExtensions` static dictionaries are filling up HOT 4
- SQLite Invalid cast from 'System.String' to 'System.Guid' HOT 4
- IDbCommandInterceptor does not fire when using BulkInsert or BulkDelete HOT 2
- WhereBulkContains does not work when table inherit from another table HOT 1
- Feat: Conditional insert HOT 3
- EFcore 8 UpdateFromQuery generates invalid sql HOT 5
- Microsoft.Data.SqlClient is on a vulnerable version - security update HOT 1
- BulkInsert ignoring session context value set before insert HOT 4
- BulkInsert - ERROR_34 HOT 11
- Z.EntityFramework.Plus.EFCore - Official behavior on DataAnnotations ? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from entityframework-extensions.