title: Memory leak when using Entity Framework
body: <p>I have a very simple application using EF. But when it runs a week, the memory usage is awful (only 80MB at first, 700MB after one week).
  When I use dotMemory to profile my application. I find the memory of Heap generation 2 is increasing all the time.</p>
  
  <p><img src="https://i.stack.imgur.com/mj2h2.jpg" alt="only run 40 minutes"></p>
  
  <p>I Get a snapshot, finally find the retained bytes of ef dbcontext is the most.</p>
  
  <p><img src="https://i.stack.imgur.com/HGPg7.jpg" alt="enter image description here"></p>
  
  <p>I am so confused. My application is so simple. Code sample：</p>
  
  <pre><code>protected CarbonBrushMonitorEntities _entities = new MYEntities();
  public void Add(HistoryData data)
  {
     _entities.HistoryDatas.Add(data);
     _entities.SaveChanges();
  }  
  </code></pre>
  
  <p><code>_entities</code> only initials once at the starting time, then used all the time.</p>
  
  <p>The function <code>Add</code> is frequently called，about 3 times/second</p>
  
  <p>I google a long time, and try some methods such as:</p>
  
  <pre><code>_entities.Configuration.ValidateOnSaveEnabled = false;
  _entities.Configuration.AutoDetectChangesEnabled = false;
  _entities.Configuration.LazyLoadingEnabled = false;
  </code></pre>
  
  <p>but these do not work.</p>