469,578 Members | 1,742 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,578 developers. It's quick & easy.

How is this a memory leak?

truefontfamily
[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.
Dec 9 '07 #1
3 1247
Ferris
101 100+
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.
Dec 9 '07 #2
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.
Dec 9 '07 #3
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/
Dec 10 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

32 posts views Thread by John | last post: by
17 posts views Thread by Josť Joye | last post: by
20 posts views Thread by jeevankodali | last post: by
14 posts views Thread by Don HO | last post: by
23 posts views Thread by James | last post: by
10 posts views Thread by Andrew Trevorrow | last post: by
1 post views Thread by dh | last post: by
6 posts views Thread by antani | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.