Skip to content

Commit

Permalink
Promptly end() the Inflater in Turbine. This will more-eagerly releas…
Browse files Browse the repository at this point in the history
…e memory allocated via JNI calls to zlib.

See the API note on the Inflater javadoc: "To release resources used by this Inflater, the end() method should be called explicitly. Subclasses are responsible for the cleanup of resources acquired by the subclass."

https://download.java.net/java/early_access/jdk24/docs/api/java.base/java/util/zip/Inflater.html

PiperOrigin-RevId: 695914851
  • Loading branch information
java-team-github-bot authored and Javac Team committed Nov 13, 2024
1 parent 3fcb10a commit 1a595dd
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions java/com/google/turbine/zip/Zip.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,9 @@ private byte[] getBytes(
byte[] bytes = new byte[(int) size];
fc.get(bytes);
if (deflate) {
bytes =
new InflaterInputStream(
new ByteArrayInputStream(bytes), new Inflater(/* nowrap= */ true))
.readAllBytes();
Inflater inf = new Inflater(/* nowrap= */ true);
bytes = new InflaterInputStream(new ByteArrayInputStream(bytes), inf).readAllBytes();
inf.end();
}
return bytes;
} catch (IOException e) {
Expand Down

0 comments on commit 1a595dd

Please sign in to comment.