title: JavaScript object/callback lifetime with `onload` event
body: <p>I am coding an image gallery tonight and this led me to a philosophical question</p>
  
  <p>I create a preloaded Image object and set an onload event for it</p>
  
  <pre><code>  ...  onmouseover = function() {
          preloadActive = true;
          imgPreload = new Image();
  
          imgPreload.onload = function() {
              preloadActive = false;
          }
  
          imgPreload.src = ...;
        }
  </code></pre>
  
  <p>Where <code>imgPreload</code> and <code>preloadActive</code> are global variables</p>
  
  <p>Now imagine that a new <code>onmouseover()</code> fires out before <code>onload()</code> executes. </p>
  
  <p>a line of code is run which creates a new image object, the old image object looses the last link and goes to Erebus, and is waiting for garbage collector to eat it.</p>
  
  <p><strong>The question goes here:</strong>
  The old object instance is not destroyed immediately. Its onload event continues to live nobody knows for how long time? Do you have any cross-browser experience about that?</p>
  
  <p>Thank you!</p>
  
  <p><em>PS: I don't worry about IE6</em></p>
  
  <hr>
  
  <p>PPS: What happens if I have an object with <strong>setInterval</strong> timeout ID inside?</p>
  
  <pre><code>obj.someVar = setInterval(...)
  </code></pre>
  
  <p>Is setInterval stopped the very moment I execute </p>
  
  <pre><code>obj = {}
  </code></pre>
  
  <p>?</p>