Entity Structure Memory Usage

The essence of the framework seems to use excessive amounts of memory when inserting new objects into the database.

for(int i = 0; i < numOwners; ++i)
{
    var owner = Owner.CreateOwner();
    db.AddToOwnerSet(owner);
    for(int j = 0; j < numChildren; ++j)
    {
        var child = Child.CreateChild();
        owner.Childs.Add(child);
    }
}
db.SaveChanges();

At this point, these objects contain very few data elements. When inserting 140,000 of these objects into the database, the total memory usage of the application was 600 MB and 1.2 gigabytes for 300,000. These objects are small, just a string name and an integer key.

I can reduce memory usage by putting SaveChanges calls in a loop, but the runtime gets a lot worse, and this is already pretty bad.

Does anyone know why an entity infrastructure uses so much memory or how to use less memory?

+5
source share
3

( ORM), , , , . , .

, , ArrayList, 256 , 257- , , , 512, 256 512, 256 . , 768 , , 257- . memystream, 3 , , . .Capacity, , 2 ( ).

, , . , 300 000 , , 524,288. , .NEt Framework, , 262145- , 262144 524288 , . 786432 . , , .

Entity concurrency, , . , , concurrency, , concurrency.

, . , . , , , , , , .

+2

, , , !

, SQL- . , ( , , ) 300 .

+2

"" , DTO - Entity Framework , , .

If you are consistently working with large object graphs, consider using something like NHibernate, which is stable, mature, and tested to work. Entity Framework is very far behind in terms of features and performance.

+1
source

All Articles