1
目前我正在创建一个Web应用程序。用户应该能够整天运行我的应用程序。目前我有一些内存问题。浏览器似乎崩溃的地方。我用是这样的结构:Javascript内存管理泄漏
function Module() {
var _me = this;
this.init = function(){
_me.setBindings(); // Using reference from Module instead of this
}
// All kind of functions
this.init();
}
其中我变为this
。
所以更复杂的情况是这样的(这实际上是我的代码大气压的一部分):
$.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
了很多。这似乎有点奇怪。
我有很多“使用范围之外的变量,范围内”。我重写了上面的代码。我看着在不同的网站这样的,但不能弄明白:
有人能解释我,如果这是正确的做法,以避免泄漏MEMOR?还是有更好的解决方案?