Recently I have to execute script retrieved thru Ajax from web server periodically. I do it by first creating a Script tag and assign the text attribute to run the script. Then, I dispose the script tag just to find out that memory keep increasing on every creation in IE 7. The following HTML illustrate the problem:
<html>
<body>
<span id='m_garbageBin'></span>
<script type="text/javascript">
function buttonClicked()
{
for (var i = 0; i < 100000; i++)
{
var sc = document.createElement("script");
sc.text = "var x=1;";
document.body.appendChild(sc);
m_garbageBin.appendChild(sc);
m_garbageBin.innerHTML = '';
}
}
</script>
<script id='m_dynamicScript' type="text/javascript">
</script>
<input type='button' value='Click me!' onclick='buttonClicked();'/>
</body>
The script isn't doing anything at all and still memory keep increasing on every click on the button in IE but not in Firefox (by using .innerHTML instead of .text). The fact that I have to retrieve the script to execute periodically cannot be changed. Anybody knows what I can do to avoid the memory increase in IE?