Experts working at Aegis Softtech would like to share their knowledge about Garbage Collection (GC) with Java Developers and community across the world. The article focuses on the basics of GC in Java. Garbage Collection (GC) is one of the most talked-about features of Java, in this article, we will explore the features and usage in detail.
Tuning the collector with Garbage Collection (GC)
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 the efficiency of collectors, 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.
Getting to know Automatic Garbage Collection
Garbage Collection (GC) is a process of looking at a high volume of memory, recognizing the in-use, and eliminating the unused objects. Here, an 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 a manual process to allocate or de-allocate the memory, whereas, in Java, Garbage Collector automatically handles the de-allocating 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 understand Garbage Collections, and you would be able to make the most of them. As they can add more value to your Java project.
For more information, email [email protected]