Java application "java.lang.OutOfMemoryError: Java heap space"
Environment
- Java (all vendors)
Issue
-
JBoss Application server stops accepting incoming requests.
-
The following message appears in the JBoss server.log file :
ERROR [STDERR] java.lang.OutOfMemoryError: Java heap space -
The following log message appears in the JBoss Operations Network (JON) server log:
Caused by: java.lang.OutOfMemoryError: Java heap space ERROR [STDERR] Exception in thread "RMI TCP Connection(44627)-127.0.0.1" ERROR [STDERR] java.lang.OutOfMemoryError: Java heap space -
We would like to root cause analysis of the heap dump generated by one of our application (GRCC) and would like to get some recommendation on heap size parameter setting.
-
Application crashes 2 times a day due to heap space full and have to be restarted
Resolution
If the heap is too small to support the application and use case, increase the maximum heap size with the -Xmx JVM option.
If there is unintended object retention, update the code to eliminate or decrease the retention.
After an OutOfMemoryError condition, the JVM can be in an unknown or unreliable state. Even if the JVM appears to be operating normally, it is recommended that you restart the Java application to ensure a clean environment. Applying KB45882 is useful to avoid the JVM going into unreliable state.
The JVM option "-XX:+HeapDumpOnOutOfMemoryError" generates a heap dump when an OOME occurs.
Root Cause
This error is caused by an undersized heap for the application's requirements or unintended object retention:
- Memory leak
- The heap size settings are not being applied as expected
- Large footprint (data per request)
- High load (number of requests)
- A cache using up memory
- finalizer thread cannot keep up with the finalizer queue
- Excessively large individual allocation by application which exceeds the configured max heap size
- execution point delay (e.g. database, messaging, accessing an external system) causing normally short lived data to get promoted to the tenured generation
- Running out of memory with heavy EJB3 use on JBoss EAP
- Java heap retention in oracle.jdbc.driver.T4CXAResource$XidListEntry
- Java heap retention in org.apache.jasper.servlet.JspServlet
- Increased memory usage during JBoss EAP buddy replication state transfer
- RepositoryClassLoader's resourceBlackList causing memory leaks in JBoss
- BaseClassLoader's blackList causing memory leaks in JBoss
- JON: Server becomes unavailable due to OutOfMemoryError: Java heap space when multiple users are accessing the web UI
- Java heap retention due to JSIP logging in JBoss Communication Platform
- JBoss - Java heap retention in org.apache.log4j.helpers.BoundedFIFO
- JBoss - Java heap retention in BodyContentImpl
- DefaultListableBeanFactorys leaking memory
- JBoss - Java heap retention in WrapperDataSourceService's 'connectionMap' HashMap
- JBoss - Java heap retention in WrapperDataSourceService's resultSetMap
- JBoss - Java heap retention in T4CPreparedStatements
- JBoss - Java heap retention in controlFlags array
- Memory usage 100% on one node in JBoss cluster
- JBoss - Java heap retention in BasicThreadPool$TimeoutInfo
- JON Agent is failing with error OutOfMemoryError: PermGen space or Java heap space
- High memory usage or OutOfMemoryException in JON Agent JBoss AS 5 plug-in
- We are seeing Hibernate store a lot of information in the Session (first level cache) and eventually see OutOfMemory exceptionshttps://access.redhat.com/
- ZipEntryContext retention in JBoss EAP 5
- Increased heap usage with forceVfsJar set
- JBoss - Java heap retention in org.jboss.ejb.EntityEnterpriseContext
- JBoss - Java heap retention in org.jboss.messaging.core.impl.MessagingQueue or other messaging destinations
- Timer Objects (BisocketServerInvoker) Accumulating in Memory
- Memory leak of JaasSecurityManager$DomainInfo in TimedCachePolicy on JBoss EAP
- XARecoveryModule leaks org.postgresql.jdbc4.Jdbc4Connection when using PostgreSQL as XA Datasource
- JBoss - Java heap retention in org.apache.catalina.session.StandardSessions
- JBoss - Java heap retention in PeriodicRecovery thread's '_xidScans' HashTable
- Memory leak in EAP 6 remoting
- JBoss - Java heap retention in org.xnio.nio.WorkerThread's delayWorkQueue
- Java heap retention in java.lang.ref.Finalizers
- Receiving 'OutOfMemory: Java heap space' due to JBoss Serialization attempting to allocate a huge StringBuffer
- JBoss leaks memory in org.jboss.remoting3.remote.RemoteConnectionProviders
- JMS session, connection, and remoting invokers accumulating in JBoss heap
- Arjuna JTA
OutOfMemoryError: Java heapwhen starting JBoss - EJB backing caches are generating large retention from cancelled tasks
- EJBTimer threads are accumulating memory in org.jboss.security.SecurityAssociation$SubjectContexts
- Memory leak in
StatelessKnowledgeSessionImplwhenfireAllRules()throws an Exception during a rule execution - Excessive Heap Consumption in com.sun.imageio.plugins.jpeg.JPEGImageWriter using OpenJDK
- Memory leak in org.apache.taglibs.standard.lang.jstl.ELEvaluator
- Seam application retaining memory in
StatefulSessionComponent - High CPU and heap usage in JBoss Session Replication with HashMaps stored as session attributes
- OutOfMemoryError due to many instances of java.lang.ref.Finalizer after upgrading OpenJDK 1.6
- High heap utilization in ExtensionManagerBuses
- BRMS throws an OOME with heap retention in ksession objects
- Compiled resource objects leak in BRMS KnowledgeAgent
- JBoss Remoting3 leaks memory in pendingInboundConnections
- Fuse Fabric console goes OOME because of accumulating org.fusesource.fabric.jaas.ZookeeperProperties
- Heap is fully consumed by BouncyCastle objects
- Heap growth from security providers stored in javax.crypto.SunJCE_b
- Memory leak in JBoss EAP 6 when highly-nested JSP tags are used / Heap retention in org.jboss.as.web.deployment.WebInjectionContainer
- Heap filling with Hibernate SessionFactoryImpls
- JBoss - Java heap retention in SharedLocalYieldingClusterLockManager
- JBoss - Java heap retention in InternalOutputBuffer
- Heap dump shows memory accumulation in one instance of org.jgroups.protocols.pbcast.NAKACK
- Heap dump shows memory accumulation in one instance of org.jgroups.protocols.FRAG3
- Verify causes OutOfMemoryError in BRMS 5
- HornetQ streaming big StreamMessages causes 'OutOfMemoryError: Java heap space'
- Large heap retention in arjuna TransactionImple
- DirectoryWatcher memory leak in ActiveMQ
- Memory leak in org.jboss.com.sun.net.httpserver.Headers
- Tomcat 6 NIO connector leaks memory
- Memory leak in AxisHttpSession
- JBoss - Java heap retention in WrappedCallableStatements
- Deadlock between SSLSocketImpl.close and SSLSocketImpl.getConnectionState
- High heap in org.hibernate.stat.ConcurrentStatisticsImpl
- OutOfMemory GC Overhead using Oracle JDBC Driver
- JBoss Fuse log:tail cause a java.lang.OutOfMemoryError: Java heap space
- Java heap retention due huge numbers of org.jboss.ejb.client.EJBClientContext
- OutOfMemoryError with CXF BusFactory as top suspect
- SQLWarning instances associated with JDBC connections consuming memory in EAP 6
- Java heap retention in Java heap retention in com.sun.jmx.mbeanserver.Repository domainTb HashMap
- DomainController experiences OOME due to many PatchArtifact$State objects
- Large heap overhead in com.sun.faces.application.view.WriteBehindStateWriters
- Large heap overhead in JBossWeb Response OutputBuffers
- Java Heap Retention in java.io.DeleteOnExitHook
- High heap retention in stdout LoggingWriter's StringBuilder buffer
- Heap consumed by many org.jboss.sun.net.httpserver.HttpConnections
- OutOfMemoryError due to large session counts in heap with ATG on EAP 7
- Java heap retention in JceSecurity's static verificationResults map
- OutOfMemory exceptions on EAP 7.2.0 with memory retention in io.undertow.server.protocol.http.HttpOpenListener
- Java heap retention in ServiceContainerImpl on EAP 7
- Large java heap growth in EJB3 SimpleCache expirationFutures
- JBoss - Java heap retention in ServletRequestContext objects referenced in sessions
- Session scoped JSF beans accumulate in WebInjectionContainer when a distributable session cache is used
- Memory Leak when Opening and Closing AMQP Consumers in the Same Session / Context
- JBoss - Java heap retention in com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporterImple
- JBoss - Java heap retention in session cache DefaultDataContainer after session listener exceptions
- Heap OutOfMemoryError with JBoss EAP Remoting SASL Authentication Memory Leak
- OOME from infinite loop in CXF WebFaultOutInterceptor
- JBoss - session.getAttribute() invocation bumps the session timeout and prevents session expiration and removal in JBoss EAP 7.x
- JBoss - HttpServerExchange accumulation with async requests on EAP 7
- Java heap and direct buffers are consumed by thousands of remoting connections created by client EJB calls
- JBoss - Java heap is consumed by org.wildfly.transaction.client.provider.remoting.TransactionClientChannel
- Sessions not removed from heap after expiration in EAP 7.4.0+
- JBoss - Java heap retention in io.undertow.servlet.util.SavedRequest
- JBoss reaching OOME during start up after update to EAP 7.4 Update 11
- JBoss - Leak in io.undertow.server.DefaultByteBufferPool on EAP 7.4.16
- OutOfMemoryError from tags leaked in WebInjectionContainer after exception
- JBoss EAP domain controller reaches OOME with large org.jboss.as.protocol.mgmt.ActiveOperationImpl overhead
- EAP SimpleCache is filling with StatefulSessionComponentInstances after updating to EAP 7.4.0+
- JBoss EAP has heap growth in com.sun.org.apache.xerces.internal.dom.DocumentImpl from CXF WebService processing after upgrading to EAP 8
- JBoss - Heap retention in org.jboss.weld.resources.ClassTransformer's enhancedAnnotatedTypes map
- JBoss - Java heap retention in StackTraceCapture
Diagnostic Steps
-
What OS and version? 32 or 64 bit?
-
What JVM and version? 32 or 64 bit?
-
How much RAM?
-
Is there available RAM to increase the heap size if necessary?
- On Linux, obtain
meminfooutput when the Java application is running:
# cat /proc/meminfo > meminfo.txt - On Linux, obtain
-
What JVM options are being used?
- On JBoss EAP, options are output to the beginning of the console log or
boot.log(EAP 4.2 CP07 and 4.3 CP06 or later). Verify the desired heap settings are being properly found and applied.
- On JBoss EAP, options are output to the beginning of the console log or
-
Is this a newly deployed application, or has it been in production for some time and only recently this issue has appeared.
-
Are there any particular circumstances surrounding when the OutOfMemoryError happens? For example, does it happen when specific functionality is executed (e.g. a file upload, a batch job, etc.), after a certain amount of time, under high load, etc.
-
Get a heap dump (How do I create a Java heap dump?) when the issue happens and analyze it (How do I analyze a Java heap dump?) to see where the retention points are.
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.