From edf34c15b79a9f37fa0354768f5e8c1549f68c0d Mon Sep 17 00:00:00 2001 From: Rael S <344980+raelg@users.noreply.github.com> Date: Thu, 28 Dec 2023 11:04:41 +0000 Subject: [PATCH 1/2] Reclaim native memory quicker by overriding close() to invoke end() on the deflater, since by supplying a deflater to the constructor of DeflaterOutputStream usesDefaultDeflater is set to false and therefore end() is not invoked in DeflaterOutputStream#close. --- .../mongodb/internal/connection/ZlibCompressor.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/driver-core/src/main/com/mongodb/internal/connection/ZlibCompressor.java b/driver-core/src/main/com/mongodb/internal/connection/ZlibCompressor.java index b2f4768b541..48d33573f3e 100644 --- a/driver-core/src/main/com/mongodb/internal/connection/ZlibCompressor.java +++ b/driver-core/src/main/com/mongodb/internal/connection/ZlibCompressor.java @@ -18,6 +18,7 @@ import com.mongodb.MongoCompressor; +import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.zip.Deflater; @@ -48,6 +49,15 @@ InputStream getInputStream(final InputStream source) { @Override OutputStream getOutputStream(final OutputStream source) { - return new DeflaterOutputStream(source, new Deflater(level)); + return new DeflaterOutputStream(source, new Deflater(level)){ + @Override + public void close() throws IOException { + try { + super.close(); + } finally { + def.end(); + } + } + }; } } From 4c689cb1ddb5b0dd0562db5ce2a59669cac3a8fb Mon Sep 17 00:00:00 2001 From: Jeff Yemin Date: Wed, 10 Jan 2024 14:13:11 -0500 Subject: [PATCH 2/2] Update driver-core/src/main/com/mongodb/internal/connection/ZlibCompressor.java --- .../main/com/mongodb/internal/connection/ZlibCompressor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver-core/src/main/com/mongodb/internal/connection/ZlibCompressor.java b/driver-core/src/main/com/mongodb/internal/connection/ZlibCompressor.java index 48d33573f3e..e826b626a79 100644 --- a/driver-core/src/main/com/mongodb/internal/connection/ZlibCompressor.java +++ b/driver-core/src/main/com/mongodb/internal/connection/ZlibCompressor.java @@ -49,7 +49,7 @@ InputStream getInputStream(final InputStream source) { @Override OutputStream getOutputStream(final OutputStream source) { - return new DeflaterOutputStream(source, new Deflater(level)){ + return new DeflaterOutputStream(source, new Deflater(level)) { @Override public void close() throws IOException { try {