title: What is the impact of C# closures on memory?
body: <p>I have a class <code>Test</code> which holds two members, one (<code>arr</code>) which takes <em>a lot of memory</em> and the other (<code>b</code>) which doesn't:</p>
  
  <pre><code>public class Test
  {
      public Test() {
          Arr = new int[100000000];
      }
      public bool B {get; private set;}
      public int[] Arr {get; private set;}
  } 
  </code></pre>
  
  <p>Later in my code, I want to store a lambda expression this way:</p>
  
  <pre><code>// `test` has been declared somewhere as an instance of Test
  Action lambda = () =&gt; {
      if (test.B)
          // Do things
  }
  </code></pre>
  
  <p>What will be the memory consumption of this closure? </p>
  
  <p><strong>Will it hold the whole <code>Test</code> object in its environment, or only <code>Test.b</code>?</strong></p>
  
  <p>Should I do instead: </p>
  
  <pre><code>var tmpB = test.B;
  Action lambda = () =&gt; {
      if (tmpB)
          // Do things
  }
  </code></pre>