Bug 24806 - addEventListener to node with closure+circular ref leaks DOM nodes
Summary: addEventListener to node with closure+circular ref leaks DOM nodes
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
Depends on:
Reported: 2009-03-25 10:37 PDT by Greg
Modified: 2009-04-11 12:54 PDT (History)
4 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Greg 2009-03-25 10:37:43 PDT
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"?>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

  <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);


Comment 1 Greg 2009-03-25 10:38:17 PDT
Does not leak in Firefox 3.x
Comment 2 David Kilzer (:ddkilzer) 2009-03-25 15:14:03 PDT
Looks like a duplicate of Bug 21260.
Comment 3 David Kilzer (:ddkilzer) 2009-04-06 15:10:08 PDT
Geoff, was this fixed by Bug 21260?