GC_
GC_

Reputation: 1673

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

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

Grae

Upvotes: 4

Views: 5323

Answers (2)

Ivo Wetzel
Ivo Wetzel

Reputation: 46735

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.

Upvotes: 2

Oded
Oded

Reputation: 498942

Setting the reference to null should free up the memory.

Upvotes: 4

Related Questions