Describe the memory heap.
The memory used for dynamic allocation is called a heap. Based on the state of the object, blocks of memory on the heap are often allocated and freed. Dead or unreferenced items are present on the heap because memory is allocated and freed in an unpredictable order. Java software called Garbage Collector frees memory for unreferenced objects.
Java objects are produced in a heap and move between parts in a timely manner in a process called generation. Depending on the age of the object, the heap memory changes between different objects. The memory heap is actually divided into three smaller generations. This format was implemented to improve the performance of the object allocation process. This object allocation behavior is beneficial for improving the overall performance of the JVM.
Figure 01: Memory Heap
Generation of memory heaps:
The heap generations are as follows:
- Young people or the new generation:
The last three sections of NewGeneration are known as Eden space, Survivor 1 space, and Survivor 2 space. When an item is first formed on the heap, memory is allocated under a new generation in Eden space, and if an object survives, moves to Survivor 1 and then to Survivor 2 after a subsequent minor garbage collection. In case of a high mortality rate of objects, small garbage collections can be optimized. - Old or Fixed Generation:
Durable goods are kept in the old generation. Typically, an age limit is specified for objects in the young generation, and when it is reached, the object is transferred to the older generation. The older generation must eventually be reunited. Here is a huge trash pickup. The memory of the previous generation was reclaimed by a large garbage collection. - Permanent Generation –
The JVM reserves and uses this space to store class and method metadata, string group information, and class-level specifications. The JVM populates the persistent generation based on the classes used by the application at runtime. Also, classes and methods from the Java SE library can be placed here.
From a garbage collection perspective, this article discusses the heap. You will learn more about how GC works in the following article.