title: C# memory usage for creating objects in a for loop
body: <p>I have a complex database conversion console app that reads from an old database, does a bunch of things, and puts into the new database.</p>
  
  <p>I'm having an escalating memory problem where my mem usage (as monitored in task manager) constantly climbs and eventually slows down the process to a halt.</p>
  
  <p>I've boiled it down to the simplest possible test POC to try and understand what's going on.</p>
  
  <pre><code>for (int i = 0; i &lt; 100000; i++)
  {
    TestObj testc = new TestObj
      {
        myTest = "testing asdf"
      };
  }
  public class TestObj
  {
      public string myTest;
  }
  </code></pre>
  
  <p>My thought was that each <code>testc</code> that is created in the loop wouldn't survive past the end of the iteration, but the way the memory is tracking it seems like the application is holding on to every instance of <code>testc</code>.</p>
  
  <p>I've done a good amount of research and experimentation but I feel like there is something I'm missing here. Shouldn't I be able to run this and have memory utilization stay rather constant?</p>