ObjectContext, not garbage collection

We perform a very simple function in a console application that goes through the databases and enumerates the table into a variable. Of course, he did more initially, but we divided it into a simple listing of 1 table.

We noticed that with each new creation, ObjectContextmemory grows by about 5 MB. We have an operator using(), and even when executed, the GC.Collect()memory is not freed.

When we delete the table listing and just create a new one ClassEntities, the memory remains very low.

We tried everything we could to destroy and collect, but to no avail, resulting in more than 1 GB of memory being used.

Here is the main program:

List < string > databases = (from x in admin_db.tblDbs select x.db_name).ToList();
foreach(var db_name in databases) {
    Console.WriteLine("Current db:" + db_name);
    var entityString = String.Format("metadata=<here we put the connection string>", db_name);
    using(ClassEntities db = new ClassEntities(entityString)) {
        try {
            List < tblDepartment > departments = db.tblDepartments.ToList();
            departments = null;
        } catch {}
    }
}

Then ClassEntities (shared):

public partial class ClassEntities: ObjectContext {
    public ClassEntities(): base("name=ClassEntities", "ClassEntities") {
        this.ContextOptions.LazyLoadingEnabled = true;
        OnContextCreated();
    }
    public ClassEntities(string connectionString): base(connectionString, "ClassEntities") {
        this.ContextOptions.LazyLoadingEnabled = true;
        OnContextCreated();
    }
    public ClassEntities(EntityConnection connection): base(connection, "ClassEntities") {
        this.ContextOptions.LazyLoadingEnabled = true;
        OnContextCreated();
    }
}

Any help or ideas would be greatly appreciated.

+4
1

2 :

, , .

, (HorekoEntitiesNoLog)

:

  • , .
  • () .
  • .
  • GC.Collect().

GC.Collect, , .

0
source

All Articles