Revision 140540 of nsCountedRef

  • Revision slug: NsCountedRef
  • Revision title: nsCountedRef
  • Revision id: 140540
  • Created:
  • Creator: Karlt
  • Is current revision? Yes
  • Comment 1 words added; page display name changed to 'nsCountedRef'

Revision Content

nsCountedRef<T> is a template class implementing an object that takes a strong reference to a reference-counted resource that must be released, typically on destruction of the object.

nsCountedRef has a role similar to nsRefPtr but does not require that the handle is a pointer to an object that has AddRef() and Release() methods. nsCountedRef is therefore useful for managing references to foreign objects.

nsCountedRef<T> is derived from nsAutoRef<T> and so inherits its methods. nsCountedRef differs from nsAutoRef in that nsCountedRef constructors add a reference to the resource, and in that nsCountedRef provides copy construction< and assignment operators enabling more than one concurrent reference to the same resource.

In order to use nsCountedRef<T> for a class T associated with a particular resource type, the type of the handle to the resource and the methods for referencing and releasing the resource must be provided for class T.  This is usually done by providing a specialization of nsAutoRefTraits<T>.

nsCountedRef<T> is defined in {{ Source("xpcom/base/nsAutoRef.h") }}.

See Also

nsAutoRef, nsAutoRefTraits

Revision Source

<p>nsCountedRef&lt;T&gt; is a template class implementing an object that takes a strong reference to a reference-counted resource that must be released, typically on destruction of the object.</p>
<p>nsCountedRef has a role similar to <a class="internal" href="/en/nsRefPtr" title="En/NsRefPtr">nsRefPtr</a> but does not require that the handle is a pointer to an object that has AddRef() and Release() methods. nsCountedRef is therefore useful for managing references to foreign objects.</p>
<p>nsCountedRef&lt;T&gt; is derived from <a class="internal" href="/En/NsAutoRef" title="En/NsAutoRef">nsAutoRef</a>&lt;T&gt; and so inherits its methods. nsCountedRef differs from nsAutoRef in that nsCountedRef constructors add a reference to the resource, and in that nsCountedRef provides copy construction&lt; and assignment operators enabling more than one concurrent reference to the same resource.</p>
<p>In order to use nsCountedRef&lt;T&gt; for a class T associated with a particular resource type, the type of the handle to the resource and the methods for referencing and releasing the resource must be provided for class T.  This is usually done by providing a specialization of <a class="internal" href="/En/NsAutoRefTraits" title="En/NsAutoRefTraits">nsAutoRefTraits</a>&lt;T&gt;.</p>
<p>nsCountedRef&lt;T&gt; is defined in {{ Source("xpcom/base/nsAutoRef.h") }}.</p>
<h3 id="See_Also">See Also</h3>
<p><a class="internal" href="/En/NsAutoRef" title="En/NsAutoRef">nsAutoRef</a>, <a class="internal" href="/En/NsAutoRefTraits" title="En/NsAutoRefTraits">nsAutoRefTraits</a></p>
Revert to this revision