title: Why does a GC after a LINQ query free the WhereListIterator but not the Func representing the condition?
body: <p>I was looking at the memory impact of a simple LINQ query and noticed that the LINQ query created 2 extra objects of types <code>Enumerable+WhereListIterator&lt;Int32&gt;</code> and <code>Func&lt;Int32, Boolean&gt;</code>. </p>
  
  <p>The code used is this:</p>
  
  <pre><code>static void Main(string[] args)
  {
      // Setting baseline snapshot
      var list1 = new List&lt;int&gt; { 4862, 6541, 7841 };
      var list2 = new List&lt;int&gt;(list1.Count);
      var list3 = new List&lt;int&gt;(list1.Count);
  
      // First snapshot: LINQ usage
      list2.AddRange(list1.Where(item =&gt; item &gt; 5000 &amp;&amp; item &lt; 7000));
  
      // Second snapshot: foreach-loop
      foreach (var item in list1)
      {
          if (item &gt; 5000 &amp;&amp; item &lt; 7000)
          {
              list3.Add(item);
          }
      }
  
      // End gather
      Console.Read();
  }
  </code></pre>
  
  <p>At the snapshot after the <code>foreach</code> loop I notice that the <code>Enumerable+WhereListIterator&lt;Int32&gt;</code> object is garbage collected but the <code>Func&lt;Int32, Boolean&gt;</code> is still in memory.</p>
  
  <p>Why is this still kept around? At that point in time (at the <code>Console.Read</code> statement) I don't think anything is still referencing it and a GC has been forced by the profiler (which is why the iterator is collected).</p>
  
  <p>Note: collecting additional snapshots does not alter how many objects are freed so it's not a matter of the <code>Func</code> being marked for collection for the next run.</p>