Package org.rocksdb

Class AbstractNativeReference

  • All Implemented Interfaces:
    java.lang.AutoCloseable
    Direct Known Subclasses:
    AbstractImmutableNativeReference, RocksMutableObject

    public abstract class AbstractNativeReference
    extends java.lang.Object
    implements java.lang.AutoCloseable
    AbstractNativeReference is the base-class of all RocksDB classes that have a pointer to a native C++ rocksdb object.

    AbstractNativeReference has the dispose() method, which frees its associated C++ object.

    This function should be called manually, however, if required it will be called automatically during the regular Java GC process via finalize().

    Note - Java can only see the long member variable (which is the C++ pointer value to the native object), as such it does not know the real size of the object and therefore may assign a low GC priority for it; So it is strongly suggested that you manually dispose of objects when you are finished with them.

    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      abstract void close()
      Frees the underlying C++ object
      void dispose()
      Deprecated.
      Instead use close()
      protected void finalize()
      Deprecated.
      You should not rely on GC of Rocks objects, and instead should either call close() manually or make use of some sort of ARM (Automatic Resource Management) such as Java 7's try-with-resources statement
      protected abstract boolean isOwningHandle()
      Returns true if we are responsible for freeing the underlying C++ object
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractNativeReference

        public AbstractNativeReference()
    • Method Detail

      • isOwningHandle

        protected abstract boolean isOwningHandle()
        Returns true if we are responsible for freeing the underlying C++ object
        Returns:
        true if we are responsible to free the C++ object
        See Also:
        dispose()
      • close

        public abstract void close()
        Frees the underlying C++ object

        It is strong recommended that the developer calls this after they have finished using the object.

        Note, that once an instance of AbstractNativeReference has been disposed, calling any of its functions will lead to undefined behavior.

        Specified by:
        close in interface java.lang.AutoCloseable
      • dispose

        @Deprecated
        public final void dispose()
        Deprecated.
        Instead use close()
      • finalize

        @Deprecated
        protected void finalize()
                         throws java.lang.Throwable
        Deprecated.
        You should not rely on GC of Rocks objects, and instead should either call close() manually or make use of some sort of ARM (Automatic Resource Management) such as Java 7's try-with-resources statement
        Simply calls dispose() to free any underlying C++ object reference which has not yet been manually released.
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable