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 close() method, which frees its associated C++ object.

    This function should be called manually, or even better, called implicitly using a try-with-resources statement, when you are finished with the object. It is no longer called automatically during the regular Java GC process via Object.finalize().

    Explanatory note - When or if the Garbage Collector calls Object.finalize() depends on the JVM implementation and system conditions, which the programmer cannot control. In addition, the GC cannot see through the native reference long member variable (which is the C++ pointer value to the native object), and cannot know what other resources depend on it.

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      abstract void close()
      Frees the underlying C++ object
      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, finalize, 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
      • 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 closed, calling any of its functions will lead to undefined behavior.

        Specified by:
        close in interface java.lang.AutoCloseable