title: Closure memory leak patterns in JavaScript
body: <p>Which of following JavaScript snippets will leak memory?</p>
  
  <p>snippet #1:</p>
  
  <pre><code>function foo(obj)
  {
      var obj2 = {};
      $('#something').click(function() { alert(obj.id); } );
  }
  </code></pre>
  
  <p>snippet #2:</p>
  
  <pre><code>function foo(obj)
  {
      var obj2 = {}
      $('#something').click(function() { alert('obj was not used.'); } );
  }
  </code></pre>
  
  <p>snippet #3:</p>
  
  <pre><code>function foo(obj)
  {
      var obj2= {id: 1}
      bar(function() { alert(obj2.id); } );
  }
  
  function bar(func)
  {
      var obj3 = {};
      func();
  }
  </code></pre>
  
  <p>and which variables won't be collected by Garbage Collector?
  How to fix leaks?</p>