InterviewSolution
| 1. |
Out Of Memory Error in Java? |
|
Answer» All the objects in Java are allocated memory from the heap memory. When an object cannot be allocated any memory because there is no more memory AVAILABLE and no memory can be obtained using the garbage collector, then the EXCEPTION OutOfMemoryError occurs in Java. The Out Of Memory Error usually occurs if there is too much data processing at a time or objects are held for too long. This exception can also occur because of problems that are out of programmer control such as an application server that doesn’t clean up after deploys A program that demonstrates the Out Of Memory Error in Java is given as FOLLOWS: IMPORT java.util.*; public class Demo { static List<String> l = new ArrayList<String>(); public static void main(String args[]) throws Exception { Integer[] arr = new Integer[5000 * 5000]; } }The output of the above program is as follows: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at Demo.main(Demo.java:9) |
|