title: Detailed Explanation of Variable Capture in Closures
body: <p>I've seen countless posts on how variable capture pulls in variables for the creation of the closure, however they all seem to stop short of specific details and call the whole thing "compiler magic".</p>
  
  <p>I'm looking for a clear-cut explanation of:</p>
  
  <ol>
  <li>How local variables are <em>actually</em> captured. </li>
  <li>The difference (if any) between capturing value types vs. reference types.</li>
  <li>And whether there is any boxing occurring with respect to value types. </li>
  </ol>
  
  <p>My preference would be for an answer in terms of values and pointers (closer to the heart of what happens internally), though I will accept a clear answer involving values and references as well.</p>