Friday, February 27, 2015

OutOfMemoryError in Java

P

java.lang.OutOfMemoryError now and then, OutOfMemoryError in Java is one problem which is more due to system's limitation (memory) rather than due to programming mistakes in most cases though in certain cases you could have memory leak which causing OutOfMemoryError. I have found that even though java.lang.OutOfMemoryError is quite common basic knowledge of its cause and solution is largely unknown among junior developers. In this article we will explore what is java.lang.OutOfMemoryError; Why OutOfMemoryError comes in Java application, different type of OutOfMemoryError and How to fix OutOfMemoryError in Java. This article is purely meant to provide basic knowledge of java.lang.OutMemoryError and won't discuss profiling in detail.

I have seen mainly two types of OutOfMemoryError in Java:

1) Java.lang.OutOfMemoryError: Java heap space
2) Java.lang.OutOfMemoryError: PermGen space

The solution to solve this problem is use options of JVM.

export JAVA_OPTS="-Xms256m -Xmx512m -XX:PermSize=64M -XX:MaxPermSize=256M"

On Windows, you can set variables environment by right clicking computer and choosing Properties



Note that, these values above just sample, you can adapt to your own project.

Reference: javarevisited

No comments:

Post a Comment