Heap memory in java

Java objects created in an area called the heap memory.The heap memory is created when the JVM starts up, heap memory is increased or decreased when an java application running. When the heap memory becomes full, garbage collector removes the unused objects, thus garbage collector makes a space for new objects.
The heap memory is divided into two areas (or generations) called
1.young space.
2.old space.
1.In young space, there is Eden space for new Object and there are two Survivor Spaces(from and to), these two Survivor Spaces are always same size.
2.Survivor Spaces are used to store survival Objects.When the young space becomes full, garbage collector removes the unused objects by running a special young collection, where all objects that have lived long enough in the young space are promoted (moved) to the old space,thus freeing up the young space for more object allocation.
3.If Eden space is full,GC will run, if any objects are live in this Eden space, those are moved to Survivor Space.
4.In young space, GC normally use Copying Algorithm, which is fast, Everytime, survival Objects are copied to one of the Survivor Space.
5.If Survivor Space is full, rest of live Objects are directly copied to Old space.
6.In Old space, GC nornally use Mark-Compact Algorithm, which is slow but requires less memory.
7.When the old space becomes full garbage is collected there, a process called an old collection.In Old space, long live time Objects stay there.
8.Out of Memory will happen there is no space for new Object even GC done for OLD or Perm part.
9.Object is moved during Garbage Collection: eden -> survivor -> tenured(old space)

Search This Blog

All the rights are reserved to this blog is belongs to me only.. Powered by Blogger.