Compare Revisions

Interfacing with the XPCOM cycle collector

Change Revisions

Revision 287280:

Revision 287280 by jlebar on

Revision 329069:

Revision 329069 by amccreight on

Title:
Interfacing with the XPCOM cycle collector
Interfacing with the XPCOM cycle collector
Slug:
Interfacing_with_the_XPCOM_cycle_collector
Interfacing_with_the_XPCOM_cycle_collector
Tags:
XPCOM, "Firefox 3"
"XPCOM", "Firefox 3"
Content:

Revision 287280
Revision 329069
n8      {{ Fx_minversion_header(3) }} This is a quick overview of tn8      This is a quick overview of the cycle collector introduced 
>he cycle collector introduced into XPCOM for Firefox 3, including>into XPCOM for Firefox 3, including a description of the steps in
> a description of the steps involved in modifying an existing C++>volved in modifying an existing C++ class to participate in XPCOM
> class to participate in XPCOM cycle collection. If you have a cl> cycle collection. If you have a class that you think is involved
>ass that you think is involved in a cyclical-ownership leak, this> in a cyclical-ownership leak, this page is for you.
> page is for you. 
n13    <h4 id="What_the_cycle_collector_does" name="What_the_cycle_cn13    <h2 id="What_the_cycle_collector_does" name="What_the_cycle_c
>ollector_does">>ollector_does">
n15    </h4>n15    </h2>
n28    <h4 id="How_the_collector_can_fail" name="How_the_collector_cn28    <h2 id="How_the_collector_can_fail" name="How_the_collector_c
>an_fail">>an_fail">
n30    </h4>n30    </h2>
n44    <h4 id="How_to_make_your_classes_participate" name="How_to_man44    <h2 id="How_to_make_your_classes_participate" name="How_to_ma
>ke_your_classes_participate">>ke_your_classes_participate">
n46    </h4>n46    </h2>
n70      <li>Change the line <code>NS_IMPL_ADDREF(nsFoo)</code> to <n70      <li>Change the line <code>NS_IMPL_ADDREF(nsFoo)</code> to <
>code>NS_IMPL_CYCLE_COLLECTING_ADDREF(nsFoo)</code> in <code>nsFoo>code>NS_IMPL_CYCLE_COLLECTING_ADDREF(nsFoo)</code> in <code>nsFoo
>.cpp</code>.>.cpp</code>, and similarly change the line <code>NS_IMPL_RELEASE(
 >nsFoo)</code> to <code>NS_IMPL_CYCLE_COLLECTING_RELEASE(nsFoo)</c
 >ode> in <code>nsFoo.cpp</code>.
71      </li>
72      <li>Change the line <code>NS_IMPL_RELEASE(nsFoo)</code> to 
><code>NS_IMPL_CYCLE_COLLECTING_RELEASE(nsFoo)</code> in <code>nsF 
>oo.cpp</code>. 
nn78    <h3>
79      Manually implementing the Traverse and Unlink methods
80    </h3>
t81      &nbsp;t82      Each field that may contain cycle collected objects needs t
 >o be passed to the cycle collector, so it can detect cycles that 
 >pass through those fields.
83    </p>
84    <p>
85      The main macro for Traverse is NS_IMPL_CYCLE_COLLECTION_TRA
 >VERSE:
86    </p>
87    <p>
88      &nbsp; NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSomeMember)
89    </p>
90    <p>
91      Unlink works similarly:
92    </p>
93    <p>
94      &nbsp; NS_IMPL_CYCLE_COLLECTION_UNLINK(mSomeMember)
95    </p>
96    <p>
97      These macros should handle a variety of cases, such as refe
 >rence counted pointers to cycle collected nsISupports or non-nsIS
 >upports objects, as well as arrays of these pointers.

Back to History