title: Memory leak Entity Framework
body: <p>I have a memory leak when I am using Entity Framework with SQL Server Compact Edition. My situation:</p>
  
  <p>I have a file about 600MByte big. I read it line by line, create a entity class and added it to the SQL Server CE database. The memory is growing very fast by it. Gen 0 Collections counter and Gen 2 Heap Size is growing very fast (info from Process Explorer). If I understand right Gen 2 Heap is for big objects. I think my entity class is a big object. So Entity Framework saves my objects and do not release them. I already try to detach them and to call GC.Collect(2) but it does not help.</p>
  
  <p>First I read the line. Then create a object after parsing the line. Then add it to the DB. Here is my database code:</p>
  
  <pre><code>DBEntities dbConnection = new DBEntities();
  dbConnection.My_Table.AddObject(MyObjectCreatedFromTheLine);
  dbConnection.SaveChanges();
  //  dbConnection.Detach(MyObjectCreatedFromTheLine);
  //  dbConnection.Dispose();
  MyObjectCreatedFromTheLine = null;
  dbConnection = null;
  </code></pre>
  
  <p>Also I read that the created entity class (<code>MyObjectCreatedFromTheLine</code>) belongs to <code>DbContext</code>. So I call this code for every line, creating each time a new context.</p>
  
  <p>What am I doing wrong?</p>