Out of Memory Exceptions

Issue

  • Jenkins suddenly crashes
  • There was an Out of Memory (OOM) exception in your Jenkins environment.
    java.lang.OutOfMemoryError [...]
    

    or

    There is insufficient memory for the Java Runtime Environment to continue.
    

Environment

Resolution

IMPORTANT: If OutOfMemory happens, Jenkins is in the undefined behavior mode. It means that anything may fail, including mission-critical threads in the master. As a result, it does not really make sense to investigate any other observed issue (i.e. connectivity between nodes, any plugin misbehaviour, etc.) before fixing OOM first.

Usually, this error is thrown when there is insufficient space to allocate an object in the Java heap. In this case, The garbage collector cannot make space available to accommodate a new object, and the heap cannot be expanded further. Also, this error may be thrown when there is insufficient physical memory or swap space to support the loading of a Java class. In a rare instance, a java.lang.OutOfMemoryError may be thrown when an excessive amount of time is being spent doing garbage collection and little memory is being freed.

To determine the cause of this exception. The text of the exception includes a detail message. There are different types of OOM Exception as you can see Java 8 - Understand the OutOfMemoryError Exception. From them, we would like to highlight in the Jenkins context ( jenkins.log):

A. Native Memory exhausted

java.lang.OutOfMemoryError: unable to create new native thread
There is insufficient memory for the Java Runtime Environment to continue.

Solution: Memory problem: ‘unable to create new native thread’
Use 64 bit Java if Windows is 64 bit. 64-bit Java offers better management of memory;
Decrease Java heap size (-Xmx/-Xms). This will free up more physical memory.
Review other running applications and close the ones no longer needed.

B. PermGen Area exhausted

java.lang.OutOfMemoryError: PermGen space

Solution: Why do I receive java.lang.OutOfMemoryError: PermGen space

C. Java Heap exhausted

java.lang.OutOfMemoryError
java.lang.OutOfMemoryError: GC overhead limit exceeded
java.lang.OutOfMemoryError: Java heap space

Solution: Java Heap Out of Memory Exception

D. Process killed by OOM Killer

In this case, the JVM crashes. The error can be spotted in /var/log/dmesg.log:

[XXXXX] Out of memory: Kill process <JENKINS_PID> (java) score <SCORE> or sacrifice child
[XXXXX] Killed process <JENKINS_PID> (java) total-vm:XXXkB, anon-rss:XXXkB, file-rss:XXXkB, shmem-rss:XXXkB

Solution: Memory Problem: Process killed by OOM Killer

Have more questions? Submit a request

2 Comments

  • 0
    Avatar
    Irmantas Marozas

    Please see the following article:

    Java Heap Out of Memory Exception <--- this is not a hyperlink

  • 0
    Avatar
    Denys Digtiar

    Thank you for letting us know, Irmantas Marozas! We have updated the article.

Please sign in to leave a comment.