[Webkit-unassigned] [Bug 17523] Javascript creating a protected object for onclick and not GCing once no-longer shown

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Sun Apr 19 23:37:47 PDT 2009


https://bugs.webkit.org/show_bug.cgi?id=17523


ggaren at apple.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |INVALID




------- Comment #6 from ggaren at apple.com  2009-04-19 23:37 PDT -------
Turns out this bug is invalid.

The reduction says:

var existingDiv = document.getElementById('test');
...
newDiv.onclick = function(){alert("You clicked me")};


The function expression assigned to the "onclick" handler implicitly captures
"existingDiv" in its scope chain / closure. So, each new div inserted into the
document references an event handler that references the last div inserted into
the document. It's a giant linked list, implicitly created by closures.

In theory, an optimizing compiler could prove that the event handler did not
actually reference "existingDiv", and optimize it out of the closure. But
that's probably beyond the scope of what this bug intended.

Work around: Remove "existingDiv" from the scope in which the event handler is
defined.


-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the webkit-unassigned mailing list