If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

*** removed my original thoughts because I just realized leak.js only contains a JavaScript comment ***

@Kor: While the HTML standard says the standard attributes don't apply to SCRIPT elements, you can still specify an Id and use getElementById to grab a reference to that node. That does work in browsers, even though it is technically invalid HTML.

I know. Sometimes browsers accept illegal syntax. But I thought that, to be sure that the syntax is not the cause of the problem, a standard code should be preferable.

Have you monitored memory usage over the period of an hour? Browsers don't immediately reclaim memory used by JavaScript. It's actually perfectly natural to see memory usage go, then back down again. How long have you monitored the browser?

This is very interesting. I played around with it and learned some things. Basically, you are trying to kill or replace the function by altering the HTML tags that defined it. This doesn't work, unless you change the src property to something different (I think) Look at this code and play with the buttons and you will see what I mean. The javascript functions defined within the script tags persist even when the code in the script tags which defined them are purged from the document.

Code:

<html>
<head>
<title>Untitled Document</title>
<script type="text/javascript">
function killer(){ // this destroys the script tags with the id of "dead"
var q = document.getElementsByTagName('script');
alert("There are: " + q.length + " script tag(s) in this document");
var x = document.getElementById("dead");
if(x == (null || undefined)){
alert("I DIDN'T FIND ANY ELEMENT WITH THAT ID--THE TAG IS GONE FROM THE DOCUMENT");
return;
}
x.parentNode.removeChild(x);
// you would think the "dead" function was gone---it isn't
}
</script>
<script type="text/javascript" id="dead">
function dead(){alert("I AM COMING FROM THE FUNCTION YOU ARE TRYING TO KILL");}
</script>
</head>
<body>
<input type="button" onclick="dead()" value = "Fire function that you trying to kill"/><br />
<input type="button" onclick = "killer()" value="Try to kill that function" /><br />
<p>Make sure to click on the last button at least twice. The second time it will indicate that there is only one script element in the document. The first time it indicates there are two. But the function that was defined by the eliminated script tags does not die.</p>
</body>
</html>

My understanding is that comments do indeed take up space in javascript, and that is one reason why they should be removed for the actual workhorse code. What I also find interesting is that the javascript here is enclosed within a SPAN tag. It might be interesting to see the number of childnodes it has as the setInterval progresses.

My understanding is that comments do indeed take up space in javascript, and that is one reason why they should be removed for the actual workhorse code. What I also find interesting is that the javascript here is enclosed within a SPAN tag. It might be interesting to see the number of childnodes it has as the setInterval progresses.

tcobb, since javascript is reference memory based, I think the button is holding a reference to the function. Just a guess. If you set the button onclick method to null in killer, it should help. I may try it to see.

In my case, I am adding a purely dynamic entity that does not take up space in the original HTML, and am trying then to remove it.

I think the route you're going now is the way to go. That's the way I would have gone, but I thought the approach you took was very fascinating. I know I didn't help you, but by trying to deal with your problem it did help me with my understanding of Javascript, for which I thank you. And just for cheap thrills, you might be interested in this as regards to dynamically created scripts:

Code:

<html>
<head>
<title>Untitled Document</title>
<script type="text/javascript">
window.onload= function(){
setTimeout(doIt, 2000);
}
function doIt(){
var x = document.getElementById("s1"); // target the element to which the script tag is a child node
x.parentNode.removeChild(x); //now kill it and its child the SCRIPT tag
x = null; //now drive a stake in its heart
var str = 'setTimeout(zap, 5000)'; // the setTimeout process does not exist yet so there is no reference to bind to
// its just a string
eval(str); //now the setTimeout process DOES exist, coming into existence after what it is supposed to bind to has been officially killed
}
</script>
</head>
<body>
<span id = "s1">Here is the span with script within it. I'll be dead in two seconds.
<script type="text/javascript">
function zap(){alert("HERE--I'M GENERATED BY THE SCRIPT THAT'S SUPPOSED TO BE DEAD.");}
</script>
</span>
<p>The moral of the story, so far as I can see it, is that javascript code that is set by the code between script tags cannot be killed by deleting the script tags that put it into existence. It will still be there. The alert box of the function
that is supposed to have been destroyed will pop up soon.</p>
</body>
</html>

That is what I really like about such forums as this. By trying to solve other people's problems we can all learn a lot. I'm sorry I couldn't help you with yours but trying to help you solve yours did teach me a lot.

The leak is classic: introduce a dynamic script DOM element, let the script execute, then remove the DOM node. Rinse. Repeat. The problem is the DOM element will not free and I cannot see any circular reference. I've tried all the tricks and can't solve it. The leak exists in both ie 6-8 and firefox.

My kit does real time updates without requiring a page reload/refresh so the leak is bothersome and can grow quickly.

I have tried moving the node to a garbage pool DIV and setting the innerHTML to "". I have tried the destroy() approach. I have stood on my head and walked with my ears.