Friday, April 26, 2019

OutOfMemoryError Exception In Java

Q- What is OutOfMemoryError Exception In Java?

OutOfMemoryError is a runtime error in Java which occurs when the Java Virtual Machine (JVM) is unable to allocate an object due to insufficient space in the Java heap. The Java Garbage Collector (GC) cannot free up the space required for a new object, which causes a java.lang.OutOfMemoryError

Understand the OutOfMemoryError Exception

Types of OutOfMemoryError in java
  1. java.lang.OutOfMemoryError: Java heap space.
  2. java.lang.OutOfMemoryError: PermGen space.
  3. java.lang.OutOfMemoryError: GC overhead limit exceeded.
  4. java.lang.OutOfMemoryError: unable to create new native thread.
  5. java.lang.OutOfMemoryError: Requested array size exceeds VM limit.
  6. java.lang.OutOfMemoryError: requested bytes for Chunk::new. Out of swap space
  7. java.lang.OutOfMemoryError: (Native method)
Q- How to resolve OutOfMemoryError exception java?

Q- Can we handle OutOfMemoryError in Java?

Q- What is a StackOverflowError?

StackOverflowException  is an runtime error
StackOverflowException is thrown for execution stack overflow errors, typically in case of a very deep or unbounded recursion. So make sure your code doesn't have an infinite loop or infinite recursion.

Q- Difference between StackOverflowError and outofmemoryerror in java?

No comments:

Post a Comment