Release resources for ZLib inflater/deflater when not used
@@ -39,6 +39,11 @@ public class CompressionCodecZLib implements CompressionCodec {
protected Deflater initialValue() throws Exception {
return new Deflater();
}
+
+ @Override
+ protected void onRemoval(Deflater deflater) throws Exception {
+ deflater.end();
+ }
};
private final FastThreadLocal<Inflater> inflater = new FastThreadLocal<Inflater>() {
@@ -46,6 +51,11 @@ public class CompressionCodecZLib implements CompressionCodec {
protected Inflater initialValue() throws Exception {
return new Inflater();
}
+
+ @Override
+ protected void onRemoval(Inflater inflater) throws Exception {
+ inflater.end();
+ }
};
@Override
