[RocksJava] RocksIterator: Assert for valid RocksDB instance & documentation

This commit is contained in:
fyrz 2014-10-27 23:53:27 +01:00
parent 56ef2caaa5
commit b08c39e14f

View File

@ -22,6 +22,11 @@ public class RocksIterator extends RocksObject {
public RocksIterator(RocksDB rocksDB, long nativeHandle) { public RocksIterator(RocksDB rocksDB, long nativeHandle) {
super(); super();
nativeHandle_ = nativeHandle; nativeHandle_ = nativeHandle;
// rocksDB must point to a valid RocksDB instance.
assert(rocksDB);
// RocksIterator must hold a reference to the related RocksDB instance
// to guarantee that while a GC cycle starts RocksDBIterator instances
// are freed prior to RocksDB instances.
rocksDB_ = rocksDB; rocksDB_ = rocksDB;
} }
@ -126,7 +131,12 @@ public class RocksIterator extends RocksObject {
} }
/** /**
* Deletes underlying C++ iterator pointer. * <p>Deletes underlying C++ iterator pointer.</p>
*
* <p>Note: the underlying handle can only be safely deleted if the RocksDB
* instance related to a certain RocksIterator is still valid and initialized.
* Therefore {@code disposeInternal()} checks if the RocksDB is initialized
* before freeing the native handle.</p>
*/ */
@Override protected void disposeInternal() { @Override protected void disposeInternal() {
assert(isInitialized()); assert(isInitialized());