Javascript JQuery ajax成功回调从不垃圾收集
请原谅我的滑稽表情。它的咖啡脚本 当我的WebApp上发生某些特定事件时,我会运行以下回调函数来启动JSON get请求:Javascript JQuery ajax成功回调从不垃圾收集,javascript,jquery,firefox,garbage-collection,mozilla,Javascript,Jquery,Firefox,Garbage Collection,Mozilla,请原谅我的滑稽表情。它的咖啡脚本 当我的WebApp上发生某些特定事件时,我会运行以下回调函数来启动JSON get请求: GmScreen.prototype.requestPcUpdate = function(id) { var currentUrl, self, url; currentUrl = window.location.href; url = currentUrl.substr(0, currentUrl.lastIndexOf('/'))
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);
}
});
};
成功回调函数如下所示:
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();
};
在回调函数中,我创建一个XML文档(以及基于它的包装器对象)并分配它。当相同id的下一次更新到达时,可以对文档和包装器对象进行垃圾收集
但这永远不会发生
在Firefox中,我发现阻止垃圾收集的主要因素是mPromiseObj
随着时间的推移,这将极大地影响我的web应用程序的性能。我怎样才能删除这件事?结果是,我的回电失败了。由于
notifyPcChangeListeners
,创建了一个新的侦听器,该侦听器最终将调用onPcUpdateReceived
因此,阻止垃圾收集清理这是完全正确的。结果是,我把回调搞砸了。由于
notifyPcChangeListeners
,创建了一个新的侦听器,该侦听器最终将调用onPcUpdateReceived
因此,阻止垃圾收集清理这些垃圾是完全正确的