What is Heap space in
Java?
When a Java program started Java Virtual Machine gets
some memory from Operating System. Java Virtual Machine or JVM uses this memory
for all its need and part of this memory is call java heap memory. Heap
in Java generally located at bottom of address space and move upwards. whenever
we create object using new operator or by any another means object is allocated
memory from Heap and When object dies, memory goes back to Heap space in
Java
(We can increase or change size of Java Heap space by
using JVM command line option -Xms,
-Xmx and –Xmn)
Java Heap and Garbage
Collection
As we know objects
are created inside heap memory and Garbage collection is a process which
removes dead objects from Java Heap space and returns memory back to Heap in
Java.
OutOfMemoryError in Java
Heap
When JVM starts JVM heap space is equal to the initial
size of Heap specified by -Xms
parameter, as application progress more objects get created and heap space is
expanded to accommodate new objects. JVM also run garbage collector
periodically to reclaim memory back from dead objects. JVM expands Heap in Java
some where near to Maximum Heap Size specified by -Xmx and if there is no more
memory left for creating new object in java heap , JVM throws
java.lang.OutOfMemoryError and your application dies. Before throwing the error, JVM
tries to run garbage collector to free any available space but even after that
not much space available on Heap in Java it results into OutOfMemoryError.
To resolve this error you need
to understand your application object profile i.e. what kind of object you are
creating, which objects are taking how much memory etc.
Oracle level.....
No comments:
Post a Comment