How do you free an XMLHttpRequest object, and how to do you free a ActiveXObject("Microsoft.XMLHTTP") object?
How do you free an XMLHttpR开发者_JAVA技巧equest object, and how to do you free a ActiveXObject("Microsoft.XMLHTTP") object?
Grae
Setting the reference to null
should free up the memory.
JavaScript has garbage collection you do not have to explicitly free objects. You could use delete variableThatHoldTheObject
or variableThatHoldTheObject = null
but that will only decrease the reference count of the object by 1
.
There might be still other references to the object. So in short, leave it to the GC to handle this for you, since you can't force it anyways.
Concerning you Comment
delete
will remove the variable and therefore the reference to the object it was pointing to.
var foo = 4;
foo; // 4
foo = null;
foo; // null
delete foo;
foo; // ReferenceError
Still, that only decreases the reference count by 1. The GC will not collect the object until its reference count reached 0. So in case there a bar
somewhere that still points to the object, it won't get collected.
精彩评论