Join MDN and developers like you at Mozilla's View Source conference, November 2-4 in Portland, Oregon. Learn more at


by 1 contributor:
この記事はまだ日本語に翻訳されていません。MDN の翻訳はボランティアによって行われています。是非 MDN に登録し、私たちの力になって下さい。

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 xpcom/base/nsAutoRef.h.

See Also

nsAutoRef, nsAutoRefTraits


Contributors to this page: Karlt
最終更新者: Karlt,