Friday 3 July 2015

Error messages related to Memory Exhausted ( Garbage Collector ) in Java

➟ Purpose

      The main purpose of this article is to understand the root cause behind different kind of error messages we generally face while our day to day coding life. Here, I am going to clear some important and most seen error messages.

➟ Class Hierarchy for Error

➟ Some Examples

➤ java.lang.OutOfMemoryError: GC Overhead limit exceeded

• It does not indicate that heap space memory is 100% full, but it's very small.
• If more than 98% of the total time is spent in garbage collection and less than 2% of the heap is recovered, then this kind of error is thrown.
• This feature is designed to prevent applications from running for an extended period of time while making little or no progress because the heap is too small.
• It can be disable using -XX:-UseGCOverheadLimit

➤ java.lang.OutOfMemoryError: Requested array size exceeds VM limit

• The application (or APIs used by that application) attempted to allocate an array that is larger than the heap size.
• For example, if an application attempts to allocate an array of 512 MB but the maximum heap size is 256 MB.

➤ java.lang.OutOfMemoryError: Java heap space

• Heap space memory is 100% full or it is less than required for allocating to new object.
• This error does not necessarily always imply a memory leak, but it can be.
• The problem can be as simple as a configuration issue, where the specified heap size (or the default size, if it is not specified) is insufficient for the application.

➤ java.lang.OutOfMemoryError: PermGen space

• It indicates the perm gen memory (subpart of heap) is full.
• It indicates it's not able to store more class or method metadata.

• It will be no more thrown while using JDK 8.

➤ java.lang.OutOfMemoryError: Metaspace

• It indicates the native memory (referred to here as metaspace) is full.
• It indicates it's not able to store more class or method metadata.
• It can be thrown while using JDK 8.

➤ java.lang.StackOverflowError

• It indicates the perm gen memory (subpart of heap) is full.
• It indicates it's not able to store more class or method metadata.


No comments :