-
Notifications
You must be signed in to change notification settings - Fork 0
Module 2: Garbage Collector
Java Memory Management Overview In Java, memory management is the process of allocating and de-allocating objects, called Memory management. Java does memory management automatically. Java uses an automatic memory management system called a garbage collector
Java Management divides into two major parts :
- JVM Memory Management
- Garbage Collection
JVM memory management is the process of allocating and de-allocating memory to objects. JVM memory management is divided into two parts:
- Stack Memory
- Heap Memory
Stack Area generates when a thread creates. It can be of either fixed or dynamic size. The stack memory is allocated per thread. It is used to store data and partial results. It contains references to heap objects. It also holds the value itself rather than a reference to an object from the heap.
It is a shared runtime data area and stores the actual object in a memory. It is created when the program starts and destroyed when the program ends. This memory is allocated for all class instances and array. Heap can be of fixed or dynamic size depending upon the system’s configuration. It is used to store the objects. There is only only one heap for a running JVM Process.
Garbage Collection
When a program executes in Java, it uses memory in different ways. The heap is a part of memory where objects live. Garbage collector makes sures to the memory is freed when the objects are no longer in use. The garbage collector is a part of the JVM. It is responsible for freeing the memory occupied by objects that are no longer in use. The garbage collector is a separate thread that runs in the background.
Working of Garbage Collector
- JVM triggers this process and as per the JVM garbage collection, process is done or else withheld. It reduces the burden of the programmer by automatically performing the allocation or deallocation of memory.
- The garbage collection process causes the rest of the processes or threads to be paused and thus is costly in nature. This problem is unacceptable for the client but can be eliminated by applying several garbage collector-based algorithms. This process of applying an algorithm is often termed Garbage Collector tuning and is important for improving the performance of a program.
