Java heap retention in java.lang.ref.Finalizer
Environment
- JBoss Enterprise Application Platform (EAP)
Issue
- JBoss throws OutOfMemoryError:
- Heap dump analysis shows heap is consumed by
java.lang.ref.Finalizer.
Resolution
- Avoid using finalize() as much as possible.
- Decrease the rate at which finalizeable objects are generated.
- Improve the execution time of finalize() calls. Avoid using any synchronization here to avoid putting the Finalizer thread into long waits/blocks.
Root Cause
- Objects with a finalize() implementation must have that method processed by the Finalizer thread before they can finally be freed. If the rate that these finalizeable objects are generated outpaces the rate at which the Finalizer processes them, then OOMEs are inevitable.
- Note that the finalizer thread has been seen in deadlocks described by Deadlock between SSLSocketImpl.close and SSLSocketImpl.getConnectionState, resulting in OOMEs from Finalizer build up.
- OutOfMemoryError due to many instances of java.lang.ref.Finalizer after upgrading OpenJDK 1.6
- Java Finalizer queue has many instances of sun.security.ssl.SSLSocketImpl
- Finalizer slowed by resteasy BaseClientResponse.finalize
- Files monitored under /webappsor conf/Catalina/ are being modified to trigger a redeployment
- High finalizer overhead in heap from org.apache.cxf.jaxws.JaxWsClientProxy
Diagnostic Steps
- Troubleshoot with a heap dump and garbage collection logging as described in Java application "java.lang.OutOfMemoryError: Java heap space" to identify the source of retention.
- Check the objects in the Finalizer queue. For example,
Java Basics / Finalizer Overviewin the Eclipse Memory Analyzer tool. - Gather multiple thread dumps over time leading to the OOME and see what kind of calls the Finalizer is making and any snags it hits.
Components
Category
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.