Skip to content

Commit

Permalink
Merge pull request #545 from apache/fix_memory_leak
Browse files Browse the repository at this point in the history
Fix memory leak.
  • Loading branch information
leerho authored Apr 12, 2024
2 parents b9284e1 + 903d15b commit 6be2938
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.common.SketchesReadOnlyException;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableHandle;
import org.apache.datasketches.memory.WritableMemory;
import org.testng.annotations.Test;

public class BloomFilterTest {

@Test
public void createNewFilterTest() {
public void createNewFilterTest() throws Exception {
// construct the same filter multiple ways
final long numItems = 4000;
final double targetFpp = 0.01;
Expand All @@ -50,12 +51,14 @@ public void createNewFilterTest() {
assertFalse(bf1.isDirect());
assertFalse(bf1.isReadOnly());

final WritableMemory wmem = WritableMemory.allocateDirect(sizeBytes).getWritable();
final BloomFilter bf2 = new BloomFilter(numBits, numHashes, seed, wmem);
assertTrue(bf2.isEmpty());
assertTrue(bf2.hasMemory());
assertTrue(bf2.isDirect());
assertFalse(bf2.isReadOnly());
try (WritableHandle wh = WritableMemory.allocateDirect(sizeBytes)) {
final WritableMemory wmem = wh.getWritable();
final BloomFilter bf2 = new BloomFilter(numBits, numHashes, seed, wmem);
assertTrue(bf2.isEmpty());
assertTrue(bf2.hasMemory());
assertTrue(bf2.isDirect());
assertFalse(bf2.isReadOnly());
}
}

@Test(expectedExceptions = SketchesArgumentException.class)
Expand Down

0 comments on commit 6be2938

Please sign in to comment.