[ 
https://issues.apache.org/jira/browse/COMPRESS-473?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16702307#comment-16702307
 ] 

Roman Leventov commented on COMPRESS-473:
-----------------------------------------

Regarding BZip2CompressorOutputStream, finalize() should just be removed 
without any replacement.

This object doesn't hold any native resources (itself), so not closing doesn't 
lead to native memory leak itself (there could be a leak if the base 
outputStream holds some native resources, but that's responsibility of that 
OutputStream implementation and that implementation should use Cleaner, not  
BZip2CompressorOutputStream).

> Avoiding Java native peer objects that override finalize()
> ----------------------------------------------------------
>
>                 Key: COMPRESS-473
>                 URL: https://issues.apache.org/jira/browse/COMPRESS-473
>             Project: Commons Compress
>          Issue Type: Improvement
>            Reporter: Roman Leventov
>            Priority: Major
>
> Objects that override finalize() are very bad for GC. The infrastructure 
> library such as Commons Compress is probably the right place to do the hard 
> work of eliminating dependencies on such objects. Instead, PhantomReference 
> registered in a Queue, or sun.misc.Cleaner (or java.lang.ref.Cleaner) should 
> be used.
> In particular:
> java.util.zip.Deflater/Inflater/ZipOutputStream/ZipInputStream/GZipOutputStream/GZipInputStream
>  should not be used.
>  
> The issue for Zstd created in a downstream library: 
> [https://github.com/luben/zstd-jni/issues/83]
>  
> Some other downstream dependencies could be affected too.
>  
> Commons Compress's own ZipFile and BZip2CompressorOutputStream classes should 
> not override finalize() too.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to