title: IServiceProvider garbage collection / disposal
body: <p>I was trying to debug a memory leak in my app (see related <a href="https://stackoverflow.com/questions/43196496/recurring-tasks-in-net-core-console-app">question</a>) and have encountered a smilingly wrong behavior.</p>
  
  <p>In this code (simplified snippet, of course):</p>
  
  <pre><code>    while (true)
      {
          using (var context = _serviceProvider.GetRequiredService&lt;IDataContext&gt;())
          {
              Console.WriteLine("Hello");
          }
      }
  </code></pre>
  
  <p>Memory consumption grows <strong>rapidly</strong>.</p>
  
  <p>If I comment out service spawn, memory consumption is stable.</p>
  
  <pre><code>    while (true)
      {
          // using (var context = _serviceProvider.GetRequiredService&lt;IDataContext&gt;())
          // {
              Console.WriteLine("Hello");
          // }
      }
  </code></pre>
  
  <p>Service was registered as <em>transient</em>.</p>
  
  <p>My understanding is that <code>using</code> statement is responsible for disposing a service. <code>var context</code> is created in the scope of <code>while</code> and should be destroyed when new iteration begins.</p>
  
  <p>My first thought was that GC just does not do its job frequently enough, but does not frequency increase when amount of consumed memory increases?</p>
  
  <p>Why am I wrong?</p>