title: Why does this code cause a memory leak in IE?
body: <p>I am reading an <a href="http://javascript.info/tutorial/memory-leaks" rel="nofollow">online JavaScript tutorial</a> in which is claimed the following code will cause memory leak in IE earlier than version 8.</p>
  
  <pre><code>function setHandler() {
    var elem = document.getElementById('id')
    elem.onclick = function() { /* ... */ }
  }
  </code></pre>
  
  <p>The author also provided the fix to prevent the memory leak:</p>
  
  <pre><code>function setHandler() {
    var elem = document.getElementById('id')
    elem.onclick = function() { /* ... */ }
    elem=null;
  }
  </code></pre>
  
  <p>Why does the original code cause a memory leak and how does the fix prevent it?</p>