<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>17523</bug_id>
          
          <creation_ts>2008-02-24 13:26:01 -0800</creation_ts>
          <short_desc>Javascript creating a protected object for onclick and not GCing once no-longer shown</short_desc>
          <delta_ts>2009-04-19 23:37:46 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore JavaScript</component>
          <version>523.x (Safari 3)</version>
          <rep_platform>Mac</rep_platform>
          <op_sys>OS X 10.5</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>INVALID</resolution>
          
          
          <bug_file_loc>http://yuuzhan.selfip.net:81/runner/?sec=view</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Shawn Stricker (kb1ibt)">kb1ibt</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>71775</commentid>
    <comment_count>0</comment_count>
    <who name="Shawn Stricker (kb1ibt)">kb1ibt</who>
    <bug_when>2008-02-24 13:26:01 -0800</bug_when>
    <thetext>On the page there are new protected objects being created for every element assigned with a onclick function. Specifically looking at the runner.js file inside the createLI function  there is an object being assigned with a function via onclick which seems to cause the object to become protected. Since that page updates every 5 seconds after a couple hours safari will report an out of memory issue in the javascript console.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>71780</commentid>
    <comment_count>1</comment_count>
      <attachid>19326</attachid>
    <who name="Shawn Stricker (kb1ibt)">kb1ibt</who>
    <bug_when>2008-02-24 13:47:45 -0800</bug_when>
    <thetext>Created attachment 19326
reduction of error

This file is a reduction of the bug, it refreshes every 5 seconds and every refresh creates a new protected object.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>71783</commentid>
    <comment_count>2</comment_count>
    <who name="Mark Rowe (bdash)">mrowe</who>
    <bug_when>2008-02-24 13:48:49 -0800</bug_when>
    <thetext>With TOT the &quot;Out of Memory&quot; error will no longer occur, but the increase in the number of protected objects is a bit suspicious.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>71784</commentid>
    <comment_count>3</comment_count>
    <who name="Mark Rowe (bdash)">mrowe</who>
    <bug_when>2008-02-24 13:49:46 -0800</bug_when>
    <thetext>&lt;rdar://problem/5762351&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85824</commentid>
    <comment_count>4</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2008-07-11 16:18:08 -0700</bug_when>
    <thetext>I don&apos;t really see how we can avoid this memory use. It would be an error to strip the element of its event handlers just because it was removed from the document, since the element can be re-added to the document.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>85825</commentid>
    <comment_count>5</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2008-07-11 16:25:05 -0700</bug_when>
    <thetext>Sorry -- I realize now that the node is no longer reachable after it&apos;s removed from the document, so, in theory, it should be GC&apos;d along with its event handler.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>118086</commentid>
    <comment_count>6</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2009-04-19 23:37:46 -0700</bug_when>
    <thetext>Turns out this bug is invalid.

The reduction says:

var existingDiv = document.getElementById(&apos;test&apos;);
...
newDiv.onclick = function(){alert(&quot;You clicked me&quot;)};


The function expression assigned to the &quot;onclick&quot; handler implicitly captures &quot;existingDiv&quot; 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&apos;s a giant linked list, implicitly created by closures.

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

Work around: Remove &quot;existingDiv&quot; from the scope in which the event handler is defined.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>19326</attachid>
            <date>2008-02-24 13:47:45 -0800</date>
            <delta_ts>2008-02-24 13:47:45 -0800</delta_ts>
            <desc>reduction of error</desc>
            <filename>test.html</filename>
            <type>text/html</type>
            <size>560</size>
            <attacher name="Shawn Stricker (kb1ibt)">kb1ibt</attacher>
            
              <data encoding="base64">PGh0bWw+CjxoZWFkPgo8c2NyaXB0Pgp2YXIgbG9hZCA9IGZ1bmN0aW9uKCl7CnNldEludGVydmFs
KHRlc3QsIDUwMDApOwp9Owp2YXIgdGVzdCA9IGZ1bmN0aW9uKCl7CnZhciBjb250ZW50ID0gZG9j
dW1lbnQuZ2V0RWxlbWVudEJ5SWQoJ2NvbnRlbnQnKTsKdmFyIGV4aXN0aW5nRGl2ID0gZG9jdW1l
bnQuZ2V0RWxlbWVudEJ5SWQoJ3Rlc3QnKTsKdmFyIG5ld0RpdiA9IGRvY3VtZW50LmNyZWF0ZUVs
ZW1lbnQoJ2RpdicpOwpuZXdEaXYuc2V0QXR0cmlidXRlKCdpZCcsJ3Rlc3QnKTsKbmV3RGl2Lmlu
bmVySFRNTCA9ICJDbGljayBNZSIKbmV3RGl2Lm9uY2xpY2sgPSBmdW5jdGlvbigpe2FsZXJ0KCJZ
b3UgY2xpY2tlZCBtZSIpfTsKaWYoZXhpc3RpbmdEaXYpewoJZXhpc3RpbmdEaXYucGFyZW50Tm9k
ZS5yZXBsYWNlQ2hpbGQobmV3RGl2LGV4aXN0aW5nRGl2KTsKCX1lbHNlewoJY29udGVudC5hcHBl
bmRDaGlsZChuZXdEaXYpOwoJfQp9Owo8L3NjcmlwdD4KPC9oZWFkPgo8Ym9keSBvbmxvYWQ9Imxv
YWQoKSI+CjxkaXYgaWQ9J2NvbnRlbnQnPjwvZGl2Pgo8L2JvZHk+CjwvaHRtbD4=
</data>

          </attachment>
      

    </bug>

</bugzilla>