public abstract class RocksObject
extends java.lang.Object
rocksdb
object.
RocksObject has dispose()
function, which releases its associated c++
resource.
This function can be either called manually, or being called automatically
during the regular Java GC process. However, since Java may wrongly assume a
RocksObject only contains a long member variable and think it is small in size,
Java may give RocksObject
low priority in the GC process. For this, it is
suggested to call dispose()
manually. However, it is safe to let
RocksObject
go out-of-scope without manually calling dispose()
as dispose()
will be called in the finalizer during the
regular GC process.
Modifier and Type | Field and Description |
---|---|
protected long |
nativeHandle_
A long variable holding c++ pointer pointing to some RocksDB C++ object.
|
Modifier | Constructor and Description |
---|---|
protected |
RocksObject() |
Modifier and Type | Method and Description |
---|---|
protected void |
disOwnNativeHandle()
Revoke ownership of the native object.
|
void |
dispose()
Release the c++ object manually pointed by the native handle.
|
protected abstract void |
disposeInternal()
The helper function of
dispose() which all subclasses of
RocksObject must implement to release their associated
C++ resource. |
protected void |
finalize()
Simply calls
dispose() and release its c++ resource if it has not
yet released. |
protected boolean |
isInitialized()
Returns true if the associated native handle has been initialized.
|
protected boolean |
isOwningNativeHandle()
Returns true if the current
RocksObject is responsible to release
its native handle. |
protected long nativeHandle_
public final void dispose()
Note that dispose()
will also be called during the GC process
if it was not called before its RocksObject
went out-of-scope.
However, since Java may wrongly wrongly assume those objects are
small in that they seems to only hold a long variable. As a result,
they might have low priority in the GC process. To prevent this,
it is suggested to call dispose()
manually.
Note that once an instance of RocksObject
has been disposed,
calling its function will lead undefined behavior.
protected abstract void disposeInternal()
dispose()
which all subclasses of
RocksObject
must implement to release their associated
C++ resource.protected void disOwnNativeHandle()
This will prevent the object from attempting to delete the underlying native object in its finalizer. This must be used when another object takes over ownership of the native object or both will attempt to delete the underlying object when garbage collected.
When disOwnNativeHandle()
is called, dispose()
will simply set
nativeHandle_
to 0 without releasing its associated C++ resource.
As a result, incorrectly use this function may cause memory leak, and this
function call will not affect the return value of isInitialized()
.
dispose()
,
isInitialized()
protected boolean isOwningNativeHandle()
RocksObject
is responsible to release
its native handle.RocksObject
is responsible to release
its native handle.disOwnNativeHandle()
,
dispose()
protected boolean isInitialized()
dispose()
protected void finalize() throws java.lang.Throwable
dispose()
and release its c++ resource if it has not
yet released.finalize
in class java.lang.Object
java.lang.Throwable