Heap is a portion of Memory where dynamic allocation and de allocations happen. Heap memory is slightly slower to read from and written to, because pointer access is needed to access heap memory. JVM allocates Java heap memory from the OS and then manages the heap for the Java application. Heap doesn't have any restrictions on memory size, it totally depends on Hardware.
Before explain the basic areas of heap, let me answer some basic questions.
In which area Java objects reside?
Java objects reside in heap.
When the heap memory creates?
Heap memory created when the JVM starts up.
Is Heap memory fixed in size?
No, heap memory size may increase or decrease in size while the application runs.
Basically Heap is divided into two areas.
a. Old space
b. Young space (Nursery)
Newly created objects are stored in young space. Whenever the young space becomes full, Java garbage collector runs, remove all the unreferenced objects. In addition to this, objects that have lived long enough in the nursery are moved to the old space, thus freeing up the nursery for more object allocation.
Old space contains objects that live long enough.When the old space becomes full, a process called an old collection collects garbage.
Thread Local area (TLA)
If the object size is small, it is usually create in Thread local area. Thread Local Area is a memory reserved from heap and given to a Java thread for exclusive use.
What happen if TLA becomes full?
Thread request for new TLA.
In following posts, I explained about different garbage collection techniques.
a. Reference Counting Approach
b. Mark-Sweep Approach
c. Copying Collectors
d. Mark-Compacting Approach
If you want to know, how to increase heap memory, go through the post ‘How to increase Heap size in java’.
You may like
Object Creation And Destruction
How to increase stack size in java
Provide for-each behavior to custom collection