Skip to content

Commit

Permalink
Reclaim native memory quicker when using ZlibCompressor (#1285)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
raelg authored Jan 10, 2024
1 parent bfb3c5b commit d80e9c1
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
};
}
}

0 comments on commit d80e9c1

Please sign in to comment.