Class ReferenceCounted<T>

java.lang.Object
io.grpc.xds.client.ReferenceCounted<T>

final class ReferenceCounted<T> extends Object
A reference count wrapper for objects. This class does not take the ownership for the object, but only provides usage counting. The real owner of the wrapped object is responsible for managing the lifecycle of the object.

Intended for a container class to keep track of lifecycle for elements it contains. This wrapper itself should never be returned to the consumers of the elements to avoid reference counts being leaked.

  • Field Details

    • instance

      private final T instance
    • refs

      private int refs
  • Constructor Details

    • ReferenceCounted

      private ReferenceCounted(T instance)
  • Method Details

    • wrap

      static <T> ReferenceCounted<T> wrap(T instance)
    • retain

      void retain()
    • release

      void release()
    • getReferenceCount

      int getReferenceCount()
    • get

      T get()