Class ReferenceCounted<T>


  • final class ReferenceCounted<T>
    extends java.lang.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 Summary

      Fields 
      Modifier and Type Field Description
      private T instance  
      private int refs  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ReferenceCounted​(T instance)  
    • Field Detail

      • instance

        private final T instance
      • refs

        private int refs
    • Constructor Detail

      • ReferenceCounted

        private ReferenceCounted​(T instance)
    • Method Detail

      • retain

        void retain()
      • release

        void release()
      • getReferenceCount

        int getReferenceCount()
      • get

        T get()