There are 9 types of java.lang.OutOfMemoryError, each signaling a unique memory-related issue within Java applications. Among these, ‘java.lang.OutOfMemoryError: Kill process (Java) or sacrifice child’ is not a common occurrence, however quite intriguing when it happens. In this post, we’ll delve into the root causes behind this error, explore potential solutions, and discuss effective diagnostic methods to troubleshoot this problem. Let’s equip ourselves with the knowledge and tools to conquer this common adversary.
Here’s a video summary of the article:
JVM Memory Regions
To better understand OutOfMemoryError, we first need to understand different JVM Memory regions. Here is a video clip that gives a good introduction about different JVM memory regions. But in nutshell, JVM has following memory regions:

- Young Generation: Newly created application objects are stored in this region.
- Old Generation: Application objects that are living for longer duration are promoted from the Young Generation to the Old Generation. Basically, this region holds long-lived objects.
- Metaspace: Class definitions, method definitions and other metadata that are required to execute your program are stored in the Metaspace region. This region was added in Java 8. Before that metadata definitions were stored in the PermGen. Since Java 8, PermGen was replaced by Metaspace.
- Threads: Each application thread requires a thread stack. Space allocated for thread stacks, which contain method call information and local variables are stored in this region.
- Code Cache: Memory areas where compiled native code (machine code) of methods is stored for efficient execution are stored in this region.
- Direct Buffer: ByteBuffer objects are used by modern framework (i.e. Spring WebClient) for efficient I/O operations. They are stored in this region.
- GC (Garbage Collection): Memory required for automatic garbage collection to work is stored in this region.
- JNI (Java Native Interface): Memory for interacting with native libraries and code written in other languages are stored in this region.
- misc: There are areas specific to certain JVM implementations or configurations, such as the internal JVM structures or reserved memory spaces, they are classified as ‘misc’ regions.
What is ‘java.lang.OutOfMemoryError: Kill process (java) or sacrifice child’?

When there is a lack of RAM capacity in the container/device, the kernel will terminate the memory consuming processes to free up the RAM. If that terminated process turns out to be a Java application, it will result in ‘java.lang.OutOfMemoryError: Kill process (java) or sacrifice child’.
What causes ‘java.lang.OutOfMemoryError: Kill process (java) or sacrifice child’?
The root cause of ‘java.lang.OutOfMemoryError: Kill process (java) or sacrifice child’ is often related to following reasons:
1. More processes in the device: When a lot of other processes are running on the container/device, it leaves less memory for the Java application to run.
2. Initial and Max Heap size set to different values: If initial heap size (i.e., -Xms) is configured at a lower value than the max heap size (i.e., -Xmx), then during runtime, Java application’s memory size will grow. If there is a lack of RAM capacity during that growth time, the kernel will terminate the Java application throwing this error.
3. Native Memory region growing: In case the initial and max heap size is set to the same value, native memory region of the JVM can grow during the runtime. If native memory is growing and there is a lack of RAM capacity, then the kernel can terminate the Java application by throwing this error
Solutions for ‘OutOfMemoryError: Kill process (java) or sacrifice child’
Following are the potential solutions to fix this error:
1. Increase RAM capacity: Try to run your application on a container/device which has larger RAM capacity.
2. Reduce other processes: Terminate (or move) other processes that are running on the container/device, so that there is enough memory for the Java application.
3. Set initial Heap and Max Heap to same value: When you set the initial heap size (i.e. -Xms) and max heap size (-Xmx) to the same value, JVM will be allocated with maximum heap size right at the startup time. Thus, JVM’s memory allocation will not grow or shrink at runtime. Kernel typically terminates the application which is constantly demanding more memory. Thus, the kernel will not terminate the Java application in the middle.
Note: Setting Initial and Max Heap size to the same value provides considerable benefits such as: Increased application availability, better performance, better Garbage Collection behaviour, faster startup time, … Learn more about the benefits of setting initial and max heap size to same value.
4. Fix Leak in Native Memory: Sometimes there could be a leak in the Native Memory as well. There could be a thread leak, or direct buffer leak – which can cause increased memory consumption. Instrument proper fix to arrest those leaks.
How to troubleshoot ‘OutOfMemoryError: Kill process (java) or sacrifice child’?
Here are the steps to troubleshoot this error:
1. Kernel log: Issue the command ‘dmesg -T’ in your command line (if you are running on Linux flavour of OS). This command will display all the kernel activities by timestamp in the console. If the kernel terminates the Java application due to this error, it will be printed here. You may also use the troubleshooting tools yCrash, which will capture 360 ° troubleshooting artifacts (GC log, thread dump, top, vmstat, iostat, netstat, disk usage, dmesg -T, …) from the application stack and identifies the root cause of the performance problem. Below is the excerpt from the yCrash report showing the ‘OutOfMemoryError: Kill process (java) or sacrifice child’ in the kernel log.
Review the Kernel log to confirm whether application was terminated because of this OutOfMemoryError.
2. Fix the memory Issue: Once OutOfMemoryError is confirmed, fix the problem using the appropriate solution that is outlined in the above section. It could be either increasing the RAM capacity, reducing other processes that are running on the container/device, setting initial & max heap size to be of same value or arresting memory leak in the native memory.
Conclusion
In this post, we’ve covered a range of topics, from understanding JVM memory regions to diagnosing and resolving ‘java.lang.OutOfMemoryError: Kill process (java) or sacrifice child’. We hope you’ve found the information useful and insightful. But our conversation doesn’t end here. Your experiences and insights are invaluable to us and to your fellow readers. We encourage you to share your encounters with ‘java.lang.OutOfMemoryError: Kill process (java) or sacrifice child’ in the comments below. Whether it’s a unique solution you’ve discovered, a best practice you swear by, or even just a personal anecdote, your contributions can enrich the learning experience for everyone.