Bug 24806
Summary: | addEventListener to node with closure+circular ref leaks DOM nodes | ||
---|---|---|---|
Product: | WebKit | Reporter: | Greg <280lifestyle> |
Component: | DOM | Assignee: | Nobody <webkit-unassigned> |
Status: | UNCONFIRMED | ||
Severity: | Normal | CC: | ddkilzer, emacemac7, ggaren, pam |
Priority: | P2 | ||
Version: | 528+ (Nightly build) | ||
Hardware: | All | ||
OS: | All |
Greg
The following JS leaks DOM nodes until the document is thrown away. Safari 4, also tested with Chrome 1.x/v8 which shows the same behavior.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>listTest</title>
<script type="text/javascript" charset="utf-8">
makeClosure= function(object) {
return function() {
return object;
}
};
gIntervalCount = 0;
myLeakyFunc = function() {
var i, widget;
console.log("myLeakyFunc: "+gIntervalCount++);
for(i=0; i<1000; i++) {
// The leak seems to be caused by an event listener on a node,
// where the listener's closure has a circular reference to the node.
widget = document.createElement('div');
widget.addEventListener('whatever', makeClosure(widget), false);
// Adding some extra chold nodes to the leaked div makes the memory leak more apparent, but is not necessary.
widget.innerHTML = '<div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div>';
}
}
window.setInterval(myLeakyFunc, 500);
</script>
</head>
<body>
</body>
</html>
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Greg
Does not leak in Firefox 3.x
David Kilzer (:ddkilzer)
Looks like a duplicate of Bug 21260.
David Kilzer (:ddkilzer)
Geoff, was this fixed by Bug 21260?
http://trac.webkit.org/changeset/42256