<?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>103242</bug_id>
          
          <creation_ts>2012-11-26 04:38:14 -0800</creation_ts>
          <short_desc>Circular reference between Document and MediaQueryMatcher.</short_desc>
          <delta_ts>2012-12-11 13:54:20 -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>New Bugs</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</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>1</everconfirmed>
          <reporter name="Marja Hölttä">marja</reporter>
          <assigned_to name="Marja Hölttä">marja</assigned_to>
          <cc>abarth</cc>
    
    <cc>ap</cc>
    
    <cc>beidson</cc>
    
    <cc>hayato</cc>
    
    <cc>jochen</cc>
    
    <cc>kenneth</cc>
    
    <cc>luiz</cc>
    
    <cc>marcoos+bwo</cc>
    
    <cc>ojan</cc>
    
    <cc>webkit.review.bot</cc>
    
    <cc>yongjun_zhang</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>775356</commentid>
    <comment_count>0</comment_count>
    <who name="Marja Hölttä">marja</who>
    <bug_when>2012-11-26 04:38:14 -0800</bug_when>
    <thetext>Document has a RefPtr&lt;MediaQueryMatcher&gt;, and in ~Document it does this:

if (m_mediaQueryMatcher)
    m_mediaQueryMatcher-&gt;documentDestroyed();

However, MediaQueryMatcher also references Document:

MediaQueryMatcher has Vector&lt;OwnPtr&lt;Listener&gt; &gt; m_listeners:
- MediaQueryMatcher::Listener has RefPtr&lt;MediaQueryListListener&gt; m_listener;
- MediaQueryListListener has ScriptValue m_value;
- In V8, ScriptValue has ScopedPersistent&lt;v8::Value&gt; m_value; and it ends up keeping the Document alive.

This reference path is cleared in MediaQueryMatcher::documentDestroyed() which destroys the MediaQueryListListeners.

So, for example, if a tab is reloaded in Chrome, and there are MediaQueryListListeners, ~Document never happens. This causes www.crbug.com/113983.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>775367</commentid>
    <comment_count>1</comment_count>
      <attachid>175973</attachid>
    <who name="Marja Hölttä">marja</who>
    <bug_when>2012-11-26 05:00:19 -0800</bug_when>
    <thetext>Created attachment 175973
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>775384</commentid>
    <comment_count>2</comment_count>
      <attachid>175973</attachid>
    <who name="WebKit Review Bot">webkit.review.bot</who>
    <bug_when>2012-11-26 05:42:06 -0800</bug_when>
    <thetext>Comment on attachment 175973
Patch

Clearing flags on attachment: 175973

Committed r135709: &lt;http://trac.webkit.org/changeset/135709&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>775385</commentid>
    <comment_count>3</comment_count>
    <who name="WebKit Review Bot">webkit.review.bot</who>
    <bug_when>2012-11-26 05:42:10 -0800</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>775555</commentid>
    <comment_count>4</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2012-11-26 09:32:42 -0800</bug_when>
    <thetext>Is it correct that a document that has been detached can never be re-attached (and we&apos;ll never have such a code path)?

&gt;     if (m_mediaQueryMatcher) 
&gt;        m_mediaQueryMatcher-&gt;documentDestroyed(); 

Calling this function from a function other than destructor is not telling the truth. You should have renamed it to documentDetached.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>775651</commentid>
    <comment_count>5</comment_count>
      <attachid>175973</attachid>
    <who name="Adam Barth">abarth</who>
    <bug_when>2012-11-26 10:48:23 -0800</bug_when>
    <thetext>Comment on attachment 175973
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=175973&amp;action=review

&gt; Source/WebCore/dom/Document.cpp:2144
&gt; +    if (m_mediaQueryMatcher)
&gt; +        m_mediaQueryMatcher-&gt;documentDestroyed();

Why does the m_mediaQueryMatcher need special handling here?  Can&apos;t it use one of our more general mechanisms for getting notified about the Document&apos;s lifecycle?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>776521</commentid>
    <comment_count>6</comment_count>
    <who name="Marja Hölttä">marja</who>
    <bug_when>2012-11-27 02:22:39 -0800</bug_when>
    <thetext>Update:

We&apos;re discussing with abarth@ what is the right way to fix this bug. So I won&apos;t do the name change documentDestroyed -&gt; documentDetached before the real fix.

This quick and dirty fix was merged to Chromium, and I&apos;m willing to work on the real fix, as soon as we figure out how it should be done.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>788761</commentid>
    <comment_count>7</comment_count>
    <who name="Yongjun Zhang">yongjun_zhang</who>
    <bug_when>2012-12-11 13:54:20 -0800</bug_when>
    <thetext>(In reply to comment #6)
&gt; Update:
&gt; 
&gt; We&apos;re discussing with abarth@ what is the right way to fix this bug. So I won&apos;t do the name change documentDestroyed -&gt; documentDetached before the real fix.
&gt; 
&gt; This quick and dirty fix was merged to Chromium, and I&apos;m willing to work on the real fix, as soon as we figure out how it should be done.

Given the fact that this circular reference is caused by matchMedia listeners, I guess we could add a method removeAllListeners to MediaQueryMatcher and call that in Document::removeAllEventListeners()?</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>175973</attachid>
            <date>2012-11-26 05:00:19 -0800</date>
            <delta_ts>2012-11-26 10:48:23 -0800</delta_ts>
            <desc>Patch</desc>
            <filename>bug-103242-20121126135758.patch</filename>
            <type>text/plain</type>
            <size>1891</size>
            <attacher name="Marja Hölttä">marja</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMTM1NzA2CmRpZmYgLS1naXQgYS9Tb3VyY2UvV2ViQ29yZS9D
aGFuZ2VMb2cgYi9Tb3VyY2UvV2ViQ29yZS9DaGFuZ2VMb2cKaW5kZXggMzJmNzE4MGExMWUyNzJk
N2NlOGYyZGRiZjVkZDA3ODkwZTcwNmIyMC4uMjQzYzNmN2Y4YWVmN2FlYmFhN2ZjZmNkODZkZTU1
NGNjNjMzZTllOSAxMDA2NDQKLS0tIGEvU291cmNlL1dlYkNvcmUvQ2hhbmdlTG9nCisrKyBiL1Nv
dXJjZS9XZWJDb3JlL0NoYW5nZUxvZwpAQCAtMSwzICsxLDIwIEBACisyMDEyLTExLTI2ICBNYXJq
YSBIw7ZsdHTDpCAgPG1hcmphQGNocm9taXVtLm9yZz4KKworICAgICAgICBDaXJjdWxhciByZWZl
cmVuY2UgYmV0d2VlbiBEb2N1bWVudCBhbmQgTWVkaWFRdWVyeU1hdGNoZXIuCisgICAgICAgIGh0
dHBzOi8vYnVncy53ZWJraXQub3JnL3Nob3dfYnVnLmNnaT9pZD0xMDMyNDIKKworICAgICAgICBS
ZXZpZXdlZCBieSBOT0JPRFkgKE9PUFMhKS4KKworICAgICAgICBJdCdzIG5vdCBlbm91Z2ggdG8g
Y2xlYW4gdXAgbGlzdGVuZXJzIGluIE1lZGlhUXVlcnlNYXRjaGVyIGluIH5Eb2N1bWVudCwKKyAg
ICAgICAgc2luY2UgTWVkaWFRdWVyeUxpc3RMaXN0ZW5lciBrZWVwcyB0aGUgRG9jdW1lbnQgYWxp
dmUuIFRoaXMgY2F1c2VkCisgICAgICAgIHd3dy5jcmJ1Zy5jb20vMTEzOTgzLgorCisgICAgICAg
IE5vIG5ldyB0ZXN0czogTm8gdmlzaWJsZSBjaGFuZ2UgaW4gYmVoYXZpb3IgKGV4Y2VwdCB0aGF0
IGl0IGRvZXNuJ3Qg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