<?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>22710</bug_id>
          
          <creation_ts>2008-12-06 04:54:36 -0800</creation_ts>
          <short_desc>Memory leak due to circular reference Document-&gt;DOMTimer-&gt;ScheduledAction-&gt;[JS objects]-&gt;Document</short_desc>
          <delta_ts>2008-12-07 18:05:59 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>DOM</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>0</everconfirmed>
          <reporter name="Dmitry Titov">dimich</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>101652</commentid>
    <comment_count>0</comment_count>
    <who name="Dmitry Titov">dimich</who>
    <bug_when>2008-12-06 04:54:36 -0800</bug_when>
    <thetext>DOMTimer::stop() will stop the timer but not release the ScheduledAction which holds to a JSFunction which can hold onto a bunch of JS wrappers They can keep a reference back to Document that owns the DOMTimer. Hence, refcount on a Document never goes to 0.
Fix is to delete the ScheduledAction in DOMTimer::stop().</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101653</commentid>
    <comment_count>1</comment_count>
      <attachid>25813</attachid>
    <who name="Dmitry Titov">dimich</who>
    <bug_when>2008-12-06 05:04:29 -0800</bug_when>
    <thetext>Created attachment 25813
proposed fix</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101654</commentid>
    <comment_count>2</comment_count>
      <attachid>25814</attachid>
    <who name="Dmitry Titov">dimich</who>
    <bug_when>2008-12-06 05:20:28 -0800</bug_when>
    <thetext>Created attachment 25814
repro file

repro file by ap@webkit.org.
Set a breakpoint at DOMTimer::stop and ~DOMTimer. Load the file and then close the window.
You should see stop() called, then ~DOMTimer() called when Document is destroyed.
Before the fix applied, you see only stop(). After the patch with fix applied, both are invoked.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101657</commentid>
    <comment_count>3</comment_count>
      <attachid>25813</attachid>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2008-12-06 07:48:19 -0800</bug_when>
    <thetext>Comment on attachment 25813
proposed fix

r=me

I don&apos;t think the added null check in DOMTimer destructor is useful, but it isn&apos;t harmful either.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101658</commentid>
    <comment_count>4</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2008-12-06 08:04:41 -0800</bug_when>
    <thetext>Committed revision 39066.

</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101762</commentid>
    <comment_count>5</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2008-12-07 15:15:07 -0800</bug_when>
    <thetext>Can we make a test case for this?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101769</commentid>
    <comment_count>6</comment_count>
    <who name="Dmitry Titov">dimich</who>
    <bug_when>2008-12-07 15:52:38 -0800</bug_when>
    <thetext>(In reply to comment #5)
&gt; Can we make a test case for this?

I think it&apos;s doable by adding a method to LayoutTestController (getJSObjectCount() which will do GCController::collect first). This way, it&apos;s possible to navigate say iframe to a test page and back and then see the number of objects alive.
But perhaps there is a simpler way that I don&apos;t see?
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101777</commentid>
    <comment_count>7</comment_count>
    <who name="Dmitry Titov">dimich</who>
    <bug_when>2008-12-07 18:05:59 -0800</bug_when>
    <thetext>Of course there is :-) Patch with test is here: bug 22730</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>25813</attachid>
            <date>2008-12-06 05:04:29 -0800</date>
            <delta_ts>2008-12-06 07:48:19 -0800</delta_ts>
            <desc>proposed fix</desc>
            <filename>patch.txt</filename>
            <type>text/plain</type>
            <size>1506</size>
            <attacher name="Dmitry Titov">dimich</attacher>
            
              <data encoding="base64">SW5kZXg6IFdlYkNvcmUvQ2hhbmdlTG9nCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIFdlYkNvcmUvQ2hhbmdlTG9n
CShyZXZpc2lvbiAzOTA2NSkKKysrIFdlYkNvcmUvQ2hhbmdlTG9nCSh3b3JraW5nIGNvcHkpCkBA
IC0xLDMgKzEsMTQgQEAKKzIwMDgtMTItMDYgIERtaXRyeSBUaXRvdiAgPGRpbWljaEBjaHJvbWl1
bS5vcmc+CisKKyAgICAgICAgUmV2aWV3ZWQgYnkgTk9CT0RZIChPT1BTISkuCisKKyAgICAgICAg
Rml4IG1lbW9yeSBsZWFrLgorICAgICAgICBodHRwczovL2J1Z3Mud2Via2l0Lm9yZy9zaG93X2J1
Zy5jZ2k/aWQ9MjI3MTAKKworICAgICAgICAqIGJpbmRpbmdzL2pzL0RPTVRpbWVyLmNwcDoKKyAg
ICAgICAgKFdlYkNvcmU6OkRPTVRpbWVyOjp+RE9NVGltZXIpOgorICAgICAgICAoV2ViQ29yZTo6
RE9NVGltZXI6OnN0b3ApOgorCiAyMDA4LTEyLTA2ICBEYXZpZCBLaWx6ZXIgIDxkZGtpbHplckBh
cHBsZS5jb20+CiAKICAgICAgICAgQnVnIDIyNjY2OiBDbGVhbiB1cCBkYXRhIHN0cnVjdHVyZXMg
dXNlZCB3aGVuIGNvbG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bW9yeSBsZWFrLgorICAgIEpTQzo6SlNMb2NrIGxvY2so
ZmFsc2UpOworICAgIGRlbGV0ZSBtX2FjdGlvbjsKKyAgICBtX2FjdGlvbiA9IDA7CiB9CiAKIHZv
aWQgRE9NVGltZXI6OnN1c3BlbmQoKSAK
</data>
<flag name="review"
          id="12095"
          type_id="1"
          status="+"
          setter="ap"
    />
          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>25814</attachid>
            <date>2008-12-06 05:20:28 -0800</date>
            <delta_ts>2008-12-06 05:20:28 -0800</delta_ts>
            <desc>repro file</desc>
            <filename>timer-leak.html</filename>
            <type>text/html</type>
            <size>53</size>
            <attacher name="Dmitry Titov">dimich</attacher>
            
              <data encoding="base64">PHNjcmlwdD4Kc2V0SW50ZXJ2YWwoZnVuY3Rpb24oKSB7fSwgMTAwMCk7Cjwvc2NyaXB0Pgo=
</data>

          </attachment>
      

    </bug>

</bugzilla>