How do you free an XMLHttpRequest object and how do you free an ActiveXObject ("Microsoft.XMLHTTP")?

How do you free an XMLHttpRequest object and how do you free an ActiveXObject ("Microsoft.XMLHTTP")?

Grae

+3
source share
2 answers

Setting a link to nullshould free memory.

+4
source

JavaScript has garbage collection you do not have to explicitly free objects. You can use delete variableThatHoldTheObjector variableThatHoldTheObject = null, but this will reduce the number of object references to 1.

There may be other object references. In short, leave this to GC to handle this for you, since you cannot force it anyway.

About You Comment

delete will delete 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 

, 1. GC , 0. , bar -, , .

+1

Source: https://habr.com/ru/post/1783880/


All Articles