[ 2 posts ]

Eric Durbin

YUI Contributor

  • Username: edurbin
  • Joined: Wed Jul 13, 2011 5:41 am
  • Posts: 50
  • GitHub: edurbin
  • Gists: edurbin
  • Offline
  • Profile

Question about node.remove() and memory leak

Post Posted: Wed Nov 30, 2011 3:58 pm
+0-
When using the following code, I get detached dom subtrees with references to objects in the chrome heap tool.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Full Page Layout - Example</title>
<script src="http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js"></script>
<script>

var counter = 0;

function populate()
{
   var data = document.createElement('div');
   data.id = 'inner';
   for(var i = 0; i < 1000; i++) {
      counter++;
      data.innerHTML += '<div id="div_' + counter + '">Blah blah ' + counter + '</div>';
   }

   document.getElementById('outer').appendChild(data);

   setTimeout("clear_data()", 5000);
}


function clear_data()
{
   YUI().use('node', function(Y) {
      //Y.one('#outer').set('innerHTML', '');
      Y.one('#inner').remove();
   });

   start_test();
}


function start_test()
{
   populate();
}


</script>

</head>

<body class=" yui-skin-sam">
<div id="top1">
   <input type="button" onclick="populate();" value="Add Data" style="z-index: 5000;">
   <input type="button" onclick="clear_data();" value="Clear Data" style="z-index: 5000;">
   <input type="button" onclick="start_test();" value="Start Test" style="z-index: 5000;">
</div>

   <div id="outer">
   </div>
</body>
</html>


According to the documentation, using node.remove(true) will destroy the node and this does eliminate the detached dom subtrees. Should removing the inner node from the parent "outer" automatically destroy the object when finished with the function, or is this a bug?

Eric Durbin

YUI Contributor

  • Username: edurbin
  • Joined: Wed Jul 13, 2011 5:41 am
  • Posts: 50
  • GitHub: edurbin
  • Gists: edurbin
  • Offline
  • Profile
Tags:

Re: Question about node.remove() and memory leak

Post Posted: Thu Dec 01, 2011 5:59 am
+0-
The longhand version results in the same behavior.

Code:
      Y.one('#outer').removeChild(Y.one('#inner'));


According to the docs, it passes this through to the dom method and the dom method doesn't exhibit this behavior, so I'm assuming this is a bug.

Quote:
removeChild
(

node

)
Node

Defined in node/js/node-imports.js:7

Passes through to DOM method.
  [ 2 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum