Improper closing of deflater object results in native memory exhaustion
 Technote (FAQ)
 
Problem
If a deflater object is not explicitly closed and ended, a native memory leak occurs. This leak can result in OutOfMemory errors and/or Java™ Virtual Machine (JVM) crashes.
 
Cause
Not explicitly closing and ending a deflater object (such as, DeflaterOutputStream, GZIPOutputStream or ZipOutputStream) causes a native memory leak. This native leak can result in OutOfMemory errors in the WebSphere® Application Server logs as well JVM hangs and crashes. The following error in the WebSphere Application Server SystemOut.log or SystemErr.log files is a clear symptom of an native issue caused by this type of deflater leak:
java.lang.OutOfMemoryError: ZIP002:OutOfMemoryError, MEM_ERROR in deflate_init2
at java.util.zip.Deflater.init(Native Method)
at java.util.zip.Deflater.<init>(Deflater.java:135)
at java.util.zip.ZipOutputStream.<init>(ZipOutputStream.java:84)
...
 
Solution
To avoid the leak, the application programmer should insure that all deflater objects are explicitly closed and ended.

The following is a code for properly ending a deflater:


Deflater zip = new Deflater(level);
DeflaterOutputStream defStream = new DeflaterOutputStream(out);
defStream.close();
zip.end();


If the application is not explicitly creating a Deflater object, Java creates a default Deflater. In this case, the application need only close the DeflaterOutputStream and this will end the default Deflater object. For example:


/// create default Deflater
DeflaterOutputStream defStream = new DeflaterOutputStream(out);
/// end the Deflater object.
defStream.close();

 
 
Cross Reference information
Segment Product Component Platform Version Edition
Application Servers Runtimes for Java Technology Java SDK
 
 


Document Information


Product categories: Software > Application Servers > Distributed Application & Web Servers > WebSphere Application Server > Out of Memory
Operating system(s): Windows
Software version: 6.0
Software edition:
Reference #: 1227106
IBM Group: Software Group
Modified date: Apr 24, 2006