jai-imageio / jai-imageio-core

JAI ImageIO Core (without javax.media.jai dependencies)
Other
234 stars 88 forks source link

Native memory leak when writing TIFFs (DEFLATE) #14

Closed PissedCapslock closed 9 years ago

PissedCapslock commented 9 years ago

When writing a TIFF using DEFLATE as compression algorithm, a java.util.zip.Deflate instance is created. This instance uses native resources, which are only released when Deflate#end() is called, or when the finalize method is invoked.

In order to avoid relying on GC to clean up the native resources through the finalizer, the TIFFDeflater class should call end() when it is disposed. In order to do this, I had to add a dispose method to the TIFFCompressor class and call it from the TIFFImageWriter.

The TIFFImageWriter already has a dispose method, which will now call the dispose method of the TIFFCompressor. As a result, everybody who is using the TIFFImageWriter class correctly (calling dispose when finished) will benefit from this fix.

Inside the TIFFImageWriter class, there was a bogusWriter created, on which the dispose call was lacking. I added this call as well.