Skip to content

Commit d80e9c1

Browse files
authored
Reclaim native memory quicker when using ZlibCompressor (#1285)
Reclaim native memory quicker by overriding close() on DeflaterOutputStream 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. JAVA-5280
1 parent bfb3c5b commit d80e9c1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

driver-core/src/main/com/mongodb/internal/connection/ZlibCompressor.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.mongodb.MongoCompressor;
2020

21+
import java.io.IOException;
2122
import java.io.InputStream;
2223
import java.io.OutputStream;
2324
import java.util.zip.Deflater;
@@ -48,6 +49,15 @@ InputStream getInputStream(final InputStream source) {
4849

4950
@Override
5051
OutputStream getOutputStream(final OutputStream source) {
51-
return new DeflaterOutputStream(source, new Deflater(level));
52+
return new DeflaterOutputStream(source, new Deflater(level)) {
53+
@Override
54+
public void close() throws IOException {
55+
try {
56+
super.close();
57+
} finally {
58+
def.end();
59+
}
60+
}
61+
};
5262
}
5363
}

0 commit comments

Comments
 (0)