javascriptjqueryfirefoxgarbage-collection

JQuery ajax success callback never garbage collected


Please excuse my funny looking JS. Its compiled Coffee Script.

When some specific things on my WebApp happen, I run the following callback function to start a JSON get request:


GmScreen.prototype.requestPcUpdate = function(id) {
      var currentUrl, self, url;
      currentUrl = window.location.href;
      url = currentUrl.substr(0, currentUrl.lastIndexOf('/')) + '.json';
      self = this;
      return $.ajax({
        url: "/chars/" + id + ".json",
        type: "GET",
        error: function() {
          return self.onPcUpdateError(this);
        },
        success: function(pc) {
          return self.onPcUpdateReceived(pc);
        }
      });
    };

The success callback function is as follows:

GmScreen.prototype.onPcUpdateReceived = function(receivedPc) {
      var pcObj;
      if (!(receivedPc['id'] in this.allPcs)) {
        console.error("No PC with ID " + receivedPc['id'] + " known!");
      }
      pcObj = this.allPcs[receivedPc['id']];
      pcObj['cmlNode'] = new CmlCharacter((new DOMParser()).parseFromString(receivedPc['cml'], 'text/xml').documentElement);
      return this.notifyPcChangeListeners();
    };

In the callback function, I create an XML document (and a wrapper object based on it) and assign it. When the next update for the same id arrives, the document and the wrapper object can be garbage collected.

But that never happens.

In Firefox, I see that the Dominator keeping this from being garbage collected is something called mPromiseObj.

Firefox Dominator View

This is drastically impacting the performance of my web app over time. How can I get this thing deleted?


Solution

  • Turns out, I screwed up my callbacks. In the cause of notifyPcChangeListeners, a new Listener was created that would have called onPcUpdateReceived eventually.

    So keeping the garbage collection from cleaning this up is completely correct.