Skip to content

Commit

Permalink
#65: Delete memory mapped buffer on close
Browse files Browse the repository at this point in the history
Unfortunately, the current solution requires a garbage collect to have been performed before the issue is resolved.
Other fixes required either a Java 8 Cleaner.clean() call not accessible from Java 21, or a Java 20 Arena.close(), which is not been finalized in Java 21.
  • Loading branch information
TomHKeysight committed Nov 27, 2024
1 parent 8bc43fc commit 3162738
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/riscure/trs/TraceSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ private void checkValid(Trace trace) {
}

private void closeReader() throws IOException {
buffer = null;
readStream.close();
}

Expand Down
5 changes: 5 additions & 0 deletions src/test/java/TestTraceSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,11 @@ void testFileReleasing() throws IOException, TRSFormatException, InterruptedExce
try (TraceSet traceSet = TraceSet.open(filePath)) {
traceSet.getMetaData().getTraceSetParameters();
}
// Unfortunately, the current solution requires a garbage collect to have been performed before the issue is resolved.
// Other fixes required either a Java 8 Cleaner.clean() call not accessible from Java 21, or a Java 20 Arena.close(),
// which is not been finalized in Java 21.
System.gc();
Thread.sleep(1000);
// Assert that the opened file has been closed again, by deleting it.
File file = new File(filePath);
assert(file.delete());
Expand Down

0 comments on commit 3162738

Please sign in to comment.