[RocksJava] DefaultColumnFamily Memory Fix

In the current implementation DefaultColumnFamily will not disown
the native handle. As the database handles the lease on the native
handle this should be the case.
main
fyrz 10 years ago
parent 22c73d15b2
commit a01b592597
  1. 5
      java/src/main/java/org/rocksdb/RocksDB.java
  2. 9
      java/src/test/java/org/rocksdb/ColumnFamilyTest.java

@ -1270,7 +1270,10 @@ public class RocksDB extends RocksObject {
* @return The handle of the default column family * @return The handle of the default column family
*/ */
public ColumnFamilyHandle getDefaultColumnFamily() { public ColumnFamilyHandle getDefaultColumnFamily() {
return new ColumnFamilyHandle(this, getDefaultColumnFamily(nativeHandle_)); ColumnFamilyHandle cfHandle = new ColumnFamilyHandle(this,
getDefaultColumnFamily(nativeHandle_));
cfHandle.disOwnNativeHandle();
return cfHandle;
} }
/** /**

@ -58,11 +58,7 @@ public class ColumnFamilyTest {
Options options = null; Options options = null;
ColumnFamilyHandle cfh = null; ColumnFamilyHandle cfh = null;
try { try {
options = new Options(); options = new Options().setCreateIfMissing(true);
options.setCreateIfMissing(true);
DBOptions dbOptions = new DBOptions();
dbOptions.setCreateIfMissing(true);
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath()); db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath());
cfh = db.getDefaultColumnFamily(); cfh = db.getDefaultColumnFamily();
@ -78,9 +74,6 @@ public class ColumnFamilyTest {
assertThat(cfh).isNotNull(); assertThat(cfh).isNotNull();
assertThat(actualValue).isEqualTo(value); assertThat(actualValue).isEqualTo(value);
} finally { } finally {
if (cfh != null) {
cfh.dispose();
}
if (db != null) { if (db != null) {
db.close(); db.close();
} }

Loading…
Cancel
Save