What happens with values in closure? JavaScript
<p>I've seen a <a href="https://www.youtube.com/watch?v=oWSQ4mWNFPU" rel="nofollow noreferrer">really cool explanation of closure.</a> So in my view closure is a way to store data somewhere. Let's see examples of closure and example without closure:</p>

<p><strong>Without closure:</strong></p>

<pre><code>function F1(x,y)
{
  var z=5;
  function F2(){
     console.log('x='+x+'y='+y+'z='+z);
  }
  F2();
}

F1(1,2)
</code></pre>

<p><strong>With closure:</strong></p>

<pre><code>function F1(x,y)
{
  var z=5;
  function F2(){
     console.log('x='+x+'y='+y+'z='+z);
  }
  return F2();
}

var p=F1(1,2)
p();
</code></pre>

<p><strong>I've understood that in closure when F1() finishes its work, then F1() clears connection to the store where values of F1 are kept. But F2() still keeps the reference to the store of values.</strong> </p>

<p><strong>Let's see images:</strong></p>

<p><strong>Without closure:</strong>
<a href="https://i.stack.imgur.com/XVtKp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XVtKp.png" alt="enter image description here"></a></p>

<p><strong>With closure:</strong>
<a href="https://i.stack.imgur.com/xcN5F.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xcN5F.png" alt="enter image description here"></a></p>

<p>I would like to know what happens in memory. I have little knowledge of C# and that reference types are reason to create objects in heap for each reference type. <strong>My question is how is it possible to store values of F2() if values of F1() are already garbage collected?</strong></p>

<p>I mean what happens in memory - how many are objects created?(JavaScript creates objects on the heap like C#?) or maybe JavaScript just uses stack to store values of functions?</p>