Improper closing of deflater object results in native memory exhaustion

Technote (troubleshooting)


Problem(Abstract)

If a deflater object is not explicitly closed and ended, a native memory leak occurs. This leak can result in OutOfMemoryError's 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 OutOfMemoryError's in the WebSphere Application Server logs as well as JVM hangs and crashes. The following error in the WebSphere Application Server SystemOut.log or SystemErr.log files is a potential indicator of a 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)
   ...


Resolving the problem

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:


try {
   Deflater zip = new Deflater(level);
   DeflaterOutputStream defStream = new DeflaterOutputStream(out);
}
finally {
   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:


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


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

Rate this page:

(0 users)Average rating

Add comments

Document information


More support for:

WebSphere Application Server
Out of Memory

Software version:

5.1.1, 6.0.2, 6.1

Operating system(s):

AIX, Linux, Windows

Software edition:

Base, Express, Network Deployment

Reference #:

1227106

Modified date:

2011-07-20

Translate my page

Machine Translation

Content navigation