Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

nsAutoRefTraits

nsAutoRefTraits<T> is a template class describing traits of resources held by objects of class nsAutoRef<T> and/or nsCountedRef<T>.

When the handle to the resource is a pointer to T the specialization may be derived from nsPointerRefTraits<T>, so that only definitions of the Release(T*) static method and possibly the AddRef(T*) static method need to be added. AddRef(T*) is necessary for nsCountedRef<T> but not for nsAutoRef<T>.

For example:

  NS_SPECIALIZE_TEMPLATE
  class nsAutoRefTraits<PRFileDesc> : public nsPointerRefTraits<PRFileDesc>
  {
  public:
      static void Release(PRFileDesc *ptr) { PR_Close(ptr); }
  };

or

  NS_SPECIALIZE_TEMPLATE
  class nsAutoRefTraits<FcPattern> : public nsPointerRefTraits<FcPattern>
  {
  public:
      static void Release(FcPattern *ptr) { FcPatternDestroy(ptr); }
      static void AddRef(FcPattern *ptr) { FcPatternReference(ptr); }
  };

nsAutoRefTraits is described in xpcom/base/nsAutoRef.h.

See Also

nsAutoRef, nsCountedRef 

Document Tags and Contributors

 Contributors to this page: teoli, Karlt
 Last updated by: Karlt,