OutOfMemoryError

Govinda Raj
2 min readAug 13, 2021

--

Let’s understand, why do we need such error?

Let’s take an example, you have a machine with 10MB RAM and you are running a java application which has already taken 6MB of that. You got a http request, where you might have to create 11 objects and each object’s size is 512KB. You have 4MB remaining, so required memory is now 512*11KB= 5.63200 megabytes, but your system has currently 4 megabytes only, so in this scenario, JVM will throw OOM error(OutOfMemoryError).

OutOfMemoryError is thrown when the Java virtual machine cannot allocate (place) an object due to insufficient memory, and the garbage collector cannot free it yet.

The memory area occupied by the java process consists of several parts as mentioned in the image. The type OutOfMemoryError depends on which of them did not have enough space.

Courtesy

java.lang.OutOfMemoryError: Java heap space

There is not enough space in the heap, namely, in the memory area in which objects created programmatically in your application are placed. The size is set by the -Xms and -Xmx parameters. If you are trying to create an object, and there is no space left in the heap, then you get this error. Typically, the problem lies in the memory leak.

java.lang.OutOfMemoryError: PermGen space

This error occurs when there is not enough space in the Permanent area, the size of which is specified by the -XX: PermSize and -XX: MaxPermSize parameters.

java.lang.OutOfMemoryError: GC overhead limit limit exceeded

This error may occur as soon as the first and second areas overflow. It is connected with the fact that there is little memory and the GC is constantly working, trying to free up some space. This error can be disabled using the -XX parameter: -UseGCOverheadLimit, but, of course, it should not be disabled, and either solve the problem of memory leakage, or allocate more volume, or change the GC settings.

java.lang.OutOfMemoryError: unable to create new native thread

Thrown when it is not possible to create more threads.

Thanks.

You can follow me on Twitter for more such contents.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Govinda Raj
Govinda Raj

Written by Govinda Raj

Senior Software Developer. Tech Enthusiast and love coding. My portfolio: https://govinda-raj.github.io/

No responses yet

Write a response