United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6223076 : Unnecessary object retention in java.util.zip.Deflater

Details
Type:
Bug
Submit Date:
2005-01-28
Status:
Resolved
Updated Date:
2010-04-03
Project Name:
JDK
Resolved Date:
2005-04-04
Component:
core-libs
OS:
generic
Sub-Component:
java.util.jar
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.3.1,1.4.2,5.0,6
Fixed Versions:
1.3.1_16 (b01)

Related Reports
Backport:
Backport:
Backport:
Relates:

Sub Tasks

Description
It's not uncommon for applications that compress large quantities of data to
pass a very large byte array to the Deflater.setInput method, either directly
or via the DeflaterOutputStream.write method.  The Deflater code saves a
reference to the given byte array in a private field, and this private field is
never cleared.  Since the Deflater class has a finalization method it can take
quite a while for a Deflater instance to be garbage collected, and in the
meantime the potentially-large byte array will be kept alive for no reason.
This has been observed to cause OutOfMemoryErrors under heavy load.

This bug is present in 1.3.1, 1.4.x, 5.0, and Mustang.

###@###.### 2005-1-28 20:22:46 GMT

                                    

Comments
SUGGESTED FIX

--- /tmp/scdiff.73CRBQ/qamnWS   2003-06-27 16:41:00.000000000 -0700
+++ src/share/classes/java/util/zip/Deflater.java       2005-01-23 19:02:15.000000000 -0800
@@ -329,15 +329,18 @@
        if (strm != 0) {
            end(strm);
            strm = 0;
+           buf = null;
        }
     }

###@###.### 2005-1-28 20:22:46 GMT
                                     
2005-01-28
EVALUATION

Yes. The Deflater class has a byte array that's not cleared specifically
up on closure of the output stream. But, it depends on GC.
De-refencing the byte array (buf) really helps from thowing OOM error in
scarce memory situations, under severe load. 

The problem is also applicable to Inflater. 

Will be fixing at both places (Inflater and Deflater) for all the applicable
releases.
###@###.### 2005-1-28 23:13:58 GMT

###@###.### 2005-1-28 23:55:42 GMT
                                     
2005-01-28



Hardware and Software, Engineered to Work Together