<?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>94324</bug_id>
          
          <creation_ts>2012-08-17 03:36:10 -0700</creation_ts>
          <short_desc>meta: Remove unnecessary RefPtr&lt;Node&gt;s from Nodes</short_desc>
          <delta_ts>2024-03-15 04:33:37 -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>DOM</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</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>
          <dependson>94330</dependson>
    
    <dependson>94335</dependson>
    
    <dependson>94336</dependson>
    
    <dependson>94338</dependson>
    
    <dependson>94339</dependson>
    
    <dependson>94340</dependson>
          <blocked>88834</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Kentaro Hara">haraken</reporter>
          <assigned_to name="Kentaro Hara">haraken</assigned_to>
          <cc>annevk</cc>
    
    <cc>ap</cc>
    
    <cc>darin</cc>
    
    <cc>morrita</cc>
    
    <cc>tkent</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>698149</commentid>
    <comment_count>0</comment_count>
    <who name="Kentaro Hara">haraken</who>
    <bug_when>2012-08-17 03:36:10 -0700</bug_when>
    <thetext>Working context: I am removing reference cycles of RefPtr&lt;Node&gt;s.

To avoid reference cycles, we want to remove unnecessary RefPtr&lt;Node&gt;s from Nodes.

One example is DateInputType::m_pickerElement:

  class DateInputType {
    RefPtr&lt;CalendarPickerElement&gt; m_pickerElement;
  };

Given that m_pickerElement is guaranteed to exist in the shadow DOM tree of a DateInputType object, m_pickerElement is guaranteed to be kept alive while the DateInputType object is alive. Note that TreeShared.h guarantees that &quot;If Node X has 1~ reference count, then all Nodes under X are kept alive&quot;. Consequently, m_pickerElement does not need to be a RefPtr&lt;Node&gt;; it can be a raw pointer.

Actually it is harmless to use RefPtr&lt;Node&gt;s for Nodes like m_pickerElement. However, there are some reasons why we want to replace these unnecessary RefPtr&lt;Node&gt;s with raw pointers:

[1] We must make sure that there are no reference cycles of RefPtr&lt;Node&gt;s. To guarantee that, we want to remove unnecessary RefPtr&lt;Node&gt;s. Think this way:

- If RefPtr&lt;Node&gt; is guaranteed to point to the subtree of &apos;this&apos; Node, it does not need to be a RefPtr&lt;Node&gt;. It can be a raw pointer.

- If RefPtr&lt;Node&gt; is not guaranteed to point to the subtree of &apos;this&apos; Node, it can potentially cause reference cycles. To avoid the reference cycles, a special trick is sometimes needed. For example, Document::m_focusedNode, Document::m_hoverNode, ...etc are implemented as RefPtr&lt;Node&gt;s but are not guaranteed to exist in the subtree of &apos;this&apos; Node. So Document implements a special trick for these RefPtr&lt;Node&gt;s to avoid reference cycles (http://code.google.com/codesearch#OAMlx_jo-ck/src/third_party/WebKit/Source/WebCore/dom/Document.cpp&amp;type=cs&amp;l=698). (Note: actually the trick has a subtle bug and it can cause a reference cycle. But the details are out of the scope of the current discussion.)

Currently, since a bunch of RefPtr&lt;Node&gt;s are used without the trick, we cannot distinguish &quot;safe&quot; RefPtr&lt;Node&gt;s from &quot;unsafe&quot; RefPtr&lt;Node&gt;s. Here &quot;unsafe&quot; means that the RefPtr&lt;Node&gt; can cause reference cycles. To resolve the confusing situation, I want to adopt the following rules:

(a) If a RefPtr&lt;Node&gt; can be safely replaced with a raw pointer (i.e. if the RefPtr&lt;Node&gt; is guaranteed to point to the subtree), the RefPtr&lt;Node&gt; should be replaced with a raw pointer.

(b) If a RefPtr&lt;Node&gt; needs to be a RefPtr&lt;Node&gt; and it can cause a reference cycle, we need to implement a trick to avoid reference cycles.

(c) If a RefPtr&lt;Node&gt; needs to be a RefPtr&lt;Node&gt; and it cannot cause a reference cycle, a comment is needed to describe that.

[2] RefPtr&lt;Node&gt;s inside one DOM tree prevent us from implementing a new DOM lifetime semantics (bug 88834).

Practically speaking, RefPtr&lt;Node&gt;s that point to a shadow DOM tree can be safely replaced with raw pointers, because the shadow DOM tree is guaranteed to exist in the subtree of &apos;this&apos; Node.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2021292</commentid>
    <comment_count>1</comment_count>
    <who name="Anne van Kesteren">annevk</who>
    <bug_when>2024-03-15 04:33:37 -0700</bug_when>
    <thetext>I&apos;m pretty sure there&apos;s no longer interest in doing this (see bug 94340 for instance).</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>