java.util.zip.(Deflater|Inflater|ZipFile) native memory leak
Environment
- OpenJDK8 derivative
- Red Hat build of OpenJDK
- Oracle JDK
Issue
- Java process size is much larger than expected.
- Java process size grows gradually, and the Java process has to be recycled periodically to release the memory.
Resolution
Decrease the Java max heap size to ensure that full GCs happen regularly.
Upgrade to JDK11+, where the finalize method is deprecated and implemented as a no-op, and memory is released when the object becomes unreachable.
Root Cause
In JDK8, the release of the native memory backing java.util.zip.(Deflater|Inflater|ZipFile) is dependent on finalization, which is dependent on regular, full GCs.
Diagnostic Steps
-
Do GC analysis and verify there are no regular, full GCs.
-
Get a heap dump and check if there are a large number of java.util.zip.(Deflater|Inflater|ZipFile) objects in the Finalization queue.
For example, if using the Eclipse Memory Analyzer Tool:
- Run the following OQL:
SELECT OBJECTS referent FROM INSTANCEOF java.lang.ref.Finalizer - Select "Show as Histogram" from top menu.
- Select "Group by Class" and "Calculate Precise Retained Size" from Histogram top menu.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.