Connecting Tech Pros Worldwide Forums | Help | Site Map

How is this a memory leak?

truefontfamily's Avatar
Newbie
 
Join Date: Dec 2007
Posts: 4
#1: Dec 9 '07
[HTML]<html>
<head>
<script type="text/javascript">
function appendRemoveTest()
{
var obj = document.createElement( 'DIV' );
document.body.appendChild( obj );
document.body.removeChild( obj );
obj.removeNode( true );
obj = null;
}
</script>
</head>

<body>
<a href="javascript:appendRemoveTest();">appendRemove Test()</a><br />
</body>
</html>[/HTML]

When I run this and click the link, Drip 0.5 gives a memory leak, but I do not understand why. I have been reading about memory leaks, but none handle a simple example as this one. Either I am overlooking something very simple or Drip is working incorrectly.

Thanks for any help.

Ferris's Avatar
Member
 
Join Date: Oct 2007
Location: Shanghai
Posts: 102
#2: Dec 9 '07

re: How is this a memory leak?


Hi

removeNode() only works in IE. Delete this line:

Expand|Select|Wrap|Line Numbers
  1. obj.removeNode( true );
  2.  
it is unnecessary,because you have used "document.removeChild()" to remove obj from the document,and "obj=null;" to free the memory.
truefontfamily's Avatar
Newbie
 
Join Date: Dec 2007
Posts: 4
#3: Dec 9 '07

re: How is this a memory leak?


Hi,

I tried that as well. Actually added the removeNode() later because I couldn't find out why it leaked. Saw it somewhere in a fix for <FORM> tags leaking when childNodes were released on IE6.

Thanks for the suggestion.
truefontfamily's Avatar
Newbie
 
Join Date: Dec 2007
Posts: 4
#4: Dec 10 '07

re: How is this a memory leak?


Ok nevermind, it is a 'bug' in Drip. It just sees any removal of an element as a possible leak.

I even ran the non-leaking example from http://www.crockford.com/javascript/memory/leak.html which according to my Drip also leaks.

Running both in Sieve shows no leaks, so I'm going with that. :-)

Spent almost an entire afternoon reading into memory leaks and trying to understand why it was leaking when it clearly wasn't. *sigh*

My advise: Get Sieve instead!

http://home.wanadoo.nl/jsrosman/
Reply


Similar JavaScript / Ajax / DHTML bytes