I have following simple program to test garbage collection using IE 5.5
<html>
<script>
var data = new Array();
function addElements()
{
if(data == null)
data = new Array();
for (var i=0; i<5000; ++i)
{
var x = data.length;
data[x] = new Object();
data[x].data1 = "hello";
data[x].data2 = "ashu";
}
numObj.value = data.length;
}
function removeElements()
{
data = new Array();
// data = null;
numObj.value = data.length;
}
</script>
<body>
<INPUT TYPE="text" NAME="numObj">
<INPUT TYPE="submit" name="add" value="add" onclick="addElements()">
<INPUT TYPE="submit" name="clear" value="clear" onclick="removeElements()">
</body>
</html>
The problem is when I click on clear button, the memory allocated on clicking on add button dosen't get cleared. The gc seems to be happening only when I click add button again. (keep task manager open --> click add 3-4 times --> click clear button --> memory used by browser dosen't reduce --> click add again --> memory used decreases)
Any idea why this is happening? Can we call gc in internet explorer explicitly? Actually in my application many javascript objects are created when application loads. I want to destroy all the unnecessary objects after it loads.
<html>
<script>
var data = new Array();
function addElements()
{
if(data == null)
data = new Array();
for (var i=0; i<5000; ++i)
{
var x = data.length;
data[x] = new Object();
data[x].data1 = "hello";
data[x].data2 = "ashu";
}
numObj.value = data.length;
}
function removeElements()
{
data = new Array();
// data = null;
numObj.value = data.length;
}
</script>
<body>
<INPUT TYPE="text" NAME="numObj">
<INPUT TYPE="submit" name="add" value="add" onclick="addElements()">
<INPUT TYPE="submit" name="clear" value="clear" onclick="removeElements()">
</body>
</html>
The problem is when I click on clear button, the memory allocated on clicking on add button dosen't get cleared. The gc seems to be happening only when I click add button again. (keep task manager open --> click add 3-4 times --> click clear button --> memory used by browser dosen't reduce --> click add again --> memory used decreases)
Any idea why this is happening? Can we call gc in internet explorer explicitly? Actually in my application many javascript objects are created when application loads. I want to destroy all the unnecessary objects after it loads.