Ticket #2531511 (closed defect)

Reporter


Eric Durbin
Opened: 11/30/11
Last modified: 01/26/12
Status: closed
Type: defect
Resolution: invalid

Owner


Matt Sweeney
Target Release: 3.5.0
Priority: P3 (normal)
Summary: node.remove() memory leak
Description:

The following code will work fine and clean up properly, however when substituting the outer.innerHTML call in clear_data with Y.one('#inner').remove(); we end up with detached dom subtrees still
being referenced in the chrome heap profiler.

<!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>

Type: defect Observed in Version: 3.4.1
Component: Node Severity: S3 (normal)
Assigned To: Matt Sweeney Target Release: 3.5.0
Location: Priority: P3 (normal)
Tags: Relates To:
Browsers: All
URL:
Test Information:

Change History

Matt Sweeney

YUI Developer

Posted: 12/14/11
  • milestone changed to 3.5.0
  • priority changed to P3 (normal)
  • status changed from new to accepted

Matt Sweeney

YUI Developer

Posted: 12/14/11
  • estimated changed from 0 to 1
  • remaining changed from 0 to 1
  • sprint changed to sprint 2

Matt Sweeney

YUI Developer

Posted: 01/26/12
  • completed changed from 0 to 0.1
  • remaining changed from 1 to 0
  • resolution changed to invalid
  • status changed from accepted to closed

Sorry I didn't reply earlier, I thought this was regarding another issue.

This is actually the expected behavior of remove(). Removing a dom node from the tree should not break any existing references. Using innerHTML, however can create orphaned dom references and event listeners.

To property clean up Y.Node references, you need to call destroy(). This wont affect the underlying dom. To remove and destroy, call remove(true). You can remove and destroy the node's entire subtree by calling empty().