Currently I am creating a web Application. Where users should be able to be running my application all day. Currently I am having some memory issues. Where the browser seems to crash. What I was using is this kind of structure:
function Module() {
var _me = this;
this.init = function(){
_me.setBindings(); // Using reference from Module instead of this
}
// All kind of functions
this.init();
}
Which I changed to this
.
So a more complex situation is this (which is actually a part of my code 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)
);
};
Now I've added the $.proxy
a lot. Which seems to be a bit strange.
I have a lot of "using variables from outside the scope, inside the scope". Which I rewrite to the above code. I've looked on different sites like this, but can't figure it out:
Can someone explain me if this is the correct approach to avoid memor leaks? Or is there a better solution?