Aegis professionals are sharing this first post about Garbage Collection (GC) with Java community and developers across the world to let them understand about the basics of GC in Java.
Your JVM (Java Virtual Machine) handles memory for your projects and it seems highly achievable with convenience, but this is not tuned by default. You need to understand some basic theory parts of the Garbage Collection to tune the collector more easily. The main concern is for efficiency of collector, i.e. how much time the program will take for program code execution instead of collecting garbage. Another point to note down is how long the application will remain on the pause mode.
You may find many opinions about garbage collection and you need to understand the algorithms in depth to escape from any trapping situation.
What exactly an Automatic Garbage Collection means?
It is a process of looking at heap memory, recognizing the in-use and eliminating the unused objects. Here, in-use object refers to some part of your program that still maintains a pointer to that object. Hence, the memory spaced by unused objects can be reclaimed.
The programming language like C uses manual process to allocate or deallocate the memory, whereas in Java, Garbage Collector will automatically handles the deallocating memory process.
Steps involve in the process:
- 1. Marking
- 2. Usual deletion
- 3. Deletion with compacting
Getting the term – Stop the world
Here, this term is used to indicate that every thread of your program (or mutator in GC speak) is paused or stopped until the operation gets completed. Garbage Collection is used to ‘Stop the World’ events.
Multiple collectors for Garbage
Java virtual machine has sorts of garbage collectors and each collector has its own features and characteristics to perform different operations. Some key collectors are:
- PS (Parallel Scavenge)- Stops the world to collect garbage in parallel
- ICMS (Incremental Concurrent Mark Sweep)- Meant for lower pauses
- G1 (Garbage First)- most stable collector
- CMS (Concurrent Mark Sweep)- possesses many phases and runs concurrently with the program
We hope all the above information will help you to understand about Garbage collections.
For further information, mail us at firstname.lastname@example.org