title: JavaScript Garbage Collection Seems to Not be Running in Chrome Extension background.html
body: <p>I am coding a Chrome extension.
  I have a $.post() command that runs on a timer in the background (setInterval).
  The callback invokes a parse function:</p>
  
  <pre><code>function parseData(new_data) {
    new_data = $.parseJSON( new_data );
    for(var x=0; x&lt;new_data.length; x++) {
      var obj = new CustomObj( new_data[x] );
      // I commented out code here in order to help isolate the problem.
    }
  }
  </code></pre>
  
  <p>CustomObj is prototyped in a typical JS manner...</p>
  
  <pre><code>function CustomObj(data){
     this.data = data;
  }
  CustomObj.prototype.getName = function() {
    return this.data.name;
  }
  // Of course, there are a few more methods here...
  </code></pre>
  
  <p>The problem:
  The extension will cause major lag. If I set it to do the $.post() every 10s (simply to speed up the appearance of the problem), within 5 minutes refreshing any tab in Chrome will show "Waiting on [My Extension]" for about 30s. Eventually the browser will more or less lock up.</p>
  
  <p>What I've discovered: if I comment out the innards of the for() loop, everything is just peachy. No lag ever. If I simply put the above line in the for(); loop (creating the CustomObj), the problem returns.</p>
  
  <p>It seems like a garbage collection problem, as far as I can tell. I've tried implicitly defining the obj variable as well as explicitly deleting it (though <a href="https://stackoverflow.com/questions/742623/deleting-objects-in-javascript">Deleting Objects in JavaScript</a> makes me believe that delete is insufficient ). Nothing seems to work.</p>
  
  <p>Thanks.</p>