【发布时间】:2014-04-08 22:46:55
【问题描述】:
目前我正在创建一个 Web 应用程序。用户应该能够整天运行我的应用程序。目前我有一些记忆问题。浏览器似乎崩溃的地方。我使用的是这种结构:
function Module() {
var _me = this;
this.init = function(){
_me.setBindings(); // Using reference from Module instead of this
}
// All kind of functions
this.init();
}
我改为this。
所以更复杂的情况是这样的(这实际上是我的代码 atm 的一部分):
$.modules.dynamic_static_webpage.prototype.addRedirect = function (anum, aeditor) {
$.prompt(
$.utils.getTranslation("Redirect"),
$.utils.getTranslation("Geef de URL op waar naar toe geredirect moet worden"),
$.proxy(function (num, editor, input) {
this.clearRedirect(editor);
var val = input.val();
if (val.indexOf("www") == 0) {
val = "http://" + val;
}
// Timeout needed, because otherwise the clear is not finished
setTimeout($.proxy(function (n, e, v) {
$.HTMLTexteditorField.setIframeSelectionHTML.call(e, "{CMS-REDIRECT" + n + "_" + v + "}");
this.redirectShow(n, v);
}, this, num, editor, val), 200);
}, this, anum, aeditor)
);
};
现在我已经添加了很多$.proxy。这似乎有点奇怪。
我有很多“使用范围外、范围内的变量”。我重写了上面的代码。我看过类似这样的不同网站,但无法弄清楚:
如果这是避免内存泄漏的正确方法,有人可以解释一下吗?还是有更好的解决方案?
【问题讨论】:
标签: javascript memory-management memory-leaks