Answer the question
In order to leave comments, you need to log in
How to fix memory leak in IE when deleting and re-creating a variable?
Actually, a question.
I'm using jQuery, I have code like this:
$("id").click(function() {<br/>
if ("perem1" in window && "perem2" in window) {<br/>
#someaction;<br/>
delete perem1;<br/>
delete perem2;<br/>
} else {<br/>
perem1= somevalue;<br/>
perem2= somevalue;<br/>
};<br/>
Answer the question
In order to leave comments, you need to log in
Variables declared without the var specifier become properties of the global window object (in the server implementation of global ).
These variables can be used with the delete statement :
property = 1;
top.property; //1
self.property; //1
window.property; //1
Math.abs; // function abs() { [native code] }
delete Math.abs; // true
Math.abs; // undefined
var variable = 10;
delete variable; // false
variable; // 10
How do you declare global variables?
Judging by the reference books, there is a big difference between the declarations:
var a = 2;
a = 2;
Hmm, thanks for the hint and updates, I'll try to predetermine it really, and then not delete it, but change the values.
But, nevertheless, if a variable is simply declared with an expression like someval = 4; (for example), it can not be deleted? Why does delete exist then?
So, I just checked, in the latest version of Chrome, everything also works correctly. Those. works in all browsers except IE (I haven't tested it on 9 yet).
It is somehow strange that a global variable cannot be deleted. It turns out, logically, all browsers work incorrectly and only IE gives an error because it knows how to do it right? Somehow this raises doubts.
Apart from the fact that it is probably better not to delete such variables, but to transfer them to undefined
(and not global ones, but, for example, in a closure), try creating and deleting them with a full indication of the "path", i.e. delete window.myvar1
.
Aaaaaaa, well, cool ... :(
In general, it works in IE9 version. Doesn't work in IE lower versions (8th and lower).
Looked under the debugger, writes "Object doesn't support this property or method". Swears on the line after "if ("perem1" in window && "perem2" in window)", where I have some manipulations with variables.
Damn. Ambush. The
idea, by the way, was not bad, to play around not by deleting, but by setting the value of the variable to null It
works, in principle, but I still can’t figure out how to change the condition (“perem1” in window && “perem2” in window) for the first and subsequent clicks.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question