@ -9,26 +9,28 @@ package org.rocksdb;
* AbstractNativeReference is the base - class of all RocksDB classes that have
* AbstractNativeReference is the base - class of all RocksDB classes that have
* a pointer to a native C + + { @code rocksdb } object .
* a pointer to a native C + + { @code rocksdb } object .
* < p >
* < p >
* AbstractNativeReference has the { @link AbstractNativeReference # disp ose( ) }
* AbstractNativeReference has the { @link AbstractNativeReference # cl ose( ) }
* method , which frees its associated C + + object . < / p >
* method , which frees its associated C + + object . < / p >
* < p >
* < p >
* This function should be called manually , however , if required it will be
* This function should be called manually , or even better , called implicitly using a
* < a
* href = "https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html" > try - with - resources < / a >
* statement , when you are finished with the object . It is no longer
* called automatically during the regular Java GC process via
* called automatically during the regular Java GC process via
* { @link AbstractNativeReference # finalize ( ) } . < / p >
* { @link AbstractNativeReference # finalize ( ) } . < / p >
* < p >
* < p >
* Note - Java can only see the long member variable ( which is the C + + pointer
* Explanatory note - When or if the Garbage Collector calls { @link Object # finalize ( ) }
* value to the native object ) , as such it does not know the real size of the
* depends on the JVM implementation and system conditions , which the programmer
* object and therefore may assign a low GC priority for it ; So it is strongly
* cannot control . In addition , the GC cannot see through the native reference
* suggested that you manually dispose of objects when you are finished with
* long member variable ( which is the C + + pointer value to the native object ) ,
* them . < / p >
* and cannot know what other resources depend on it .
* < / p >
* /
* /
public abstract class AbstractNativeReference implements AutoCloseable {
public abstract class AbstractNativeReference implements AutoCloseable {
/ * *
/ * *
* Returns true if we are responsible for freeing the underlying C + + object
* Returns true if we are responsible for freeing the underlying C + + object
*
*
* @return true if we are responsible to free the C + + object
* @return true if we are responsible to free the C + + object
* @see # dispose ( )
* /
* /
protected abstract boolean isOwningHandle ( ) ;
protected abstract boolean isOwningHandle ( ) ;
@ -39,38 +41,8 @@ public abstract class AbstractNativeReference implements AutoCloseable {
* have finished using the object . < / p >
* have finished using the object . < / p >
* < p >
* < p >
* Note , that once an instance of { @link AbstractNativeReference } has been
* Note , that once an instance of { @link AbstractNativeReference } has been
* disp osed, calling any of its functions will lead to undefined
* cl osed, calling any of its functions will lead to undefined
* behavior . < / p >
* behavior . < / p >
* /
* /
@Override
@Override public abstract void close ( ) ;
public abstract void close ( ) ;
/ * *
* @deprecated Instead use { @link AbstractNativeReference # close ( ) }
* /
@Deprecated
public final void dispose ( ) {
close ( ) ;
}
/ * *
* Simply calls { @link AbstractNativeReference # dispose ( ) } to free
* any underlying C + + object reference which has not yet been manually
* released .
*
* @deprecated You should not rely on GC of Rocks objects , and instead should
* either call { @link AbstractNativeReference # close ( ) } manually or make
* use of some sort of ARM ( Automatic Resource Management ) such as
* Java 7 ' s < a href = "https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html" > try - with - resources < / a >
* statement
* /
@Override
@Deprecated
protected void finalize ( ) throws Throwable {
if ( isOwningHandle ( ) ) {
//TODO(AR) log a warning message... developer should have called close()
}
dispose ( ) ;
super . finalize ( ) ;
}
}
}