title: IronPython memory leak?
body: <p>Run this:</p>
  
  <pre><code>for i in range(1000000000):
      a = []
  </code></pre>
  
  <p>It looks like the list objects being created never get marked for garbage collection. From a memory profiler, it looks like the interpreter's stack frame is holding onto all the list objects, so GC can never do anything about it.</p>
  
  <p>Is this by design?</p>
  
  <p>EDIT:</p>
  
  <p>Here is a better example of the problem. Run the code below with a memory profiler:</p>
  
  <pre><code>a = [b for b in range(1000000)]
  a = [b for b in range(1000000)]
  a = [b for b in range(1000000)]
  a = [b for b in range(1000000)]
  a = [b for b in range(1000000)]
  a = [b for b in range(1000000)]
  a = [b for b in range(1000000)]
  </code></pre>
  
  <p>You will see that the memory allocated during the list comprehensions never gets garbage collected. This is because all the objects created are being referenced by an InterpreterFrame object in the DLR.</p>
  
  <p>Now run this:</p>
  
  <pre><code>def get():
      return [b for b in range(1000000)]
  
  a = get()
  a = get()
  a = get()
  a = get()
  a = get()
  a = get()
  a = get()
  </code></pre>
  
  <p>Under a profiler, you can see that the memory here does get garbage collected as it should. I am guessing this works because the InterpreterFrame of the function is cleared when the function exits.</p>
  
  <p>So, is this a bug? This seems that it will lead to some pretty bad memory leaks when within frames (contexts?) of an IronPython script.</p>