title: Entity framework memory not released
body: <p>I'm using a very simple asp.net mvc application with Entity Framework 6.0.2, .Net 4.5.1:</p>
  
  <pre><code>public class HomeController : Controller
  {
     public ActionResult Index()
     {
        int count;
        using (var db = new LocalContext())
        {
           count = db.Counters.Count();
        }
        return View(count);
     }
  }
  
  public class Counter
  {
     public int Id { get; set; }
  }
  
  public class LocalContext : DbContext
  {
     public DbSet&lt;Counter&gt; Counters { get; set; }
  }
  </code></pre>
  
  <p>If I do a load test on it, I eventually get an Out Of Memory Exception. (<code>tinyget -srv:localhost -port:&lt;port&gt; -uri:/home/index/ -threads:30 -loop:5000</code>). In Performance monitor I see the generation 2 Heap steadily grow. If I use a smaller loop value (say 500), the size grows until tinyget stops. Then the heap size stays the same (for at least 20 minutes, after that I stopped the server).</p>
  
  <p>What am I doing wrong?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>So I tried Simon Mouriers suggestion and left out the EF code. Then I don't have memory problems. So I thought, maybe if I use Release instead of Debug, it will make a difference. And it did! Memory was released after a while and I could put high load on the site. Then I switched back to Debug to see if I could get more info and... even in Debug mode no problems anymore. FML, I worked a day on it and now I can't reproduce it anymore.</p>