What is the use of Garbage Collection in Java?
There are two stages to garbage collection.
1. Marking: The garbage collector traverses the application graph, starting from the root objects. Each object that the garbage collector encounters is marked as used and will not be deleted in the next stage.
2. Sweeping: The objects that were marked in the Marking stage are deleted here. There are multiple algorithms for deleting depending on the size and fragmentation of the memory.
In any application some objects are short-lived and some are long-lived. Garbage collection can take advantage of this information and split the memory space in to two sections: young generation and old generation. The objects that are short-lived are place in young generation and long-lived once are placed in old generation. This approach is called Generational garbage collection.
Â
What is the use of Garbage Collection in Java?
Thanks for that information. I also wanted to know what are the various jvm arguments available for garbage collection?
What is the use of Garbage Collection in Java?
Here are some of the most commonly used GC params to the JVM:
-XX:-DisableExplicitGCÂ Â Â Â Â Â Disable calls to System.gc(), JVM still performs garbage collection when necessary.
-XX:-UseParallelGCÂ Â Â Â Â Â Â Â Â Â Use parallel garbage collection for scavenges.
-XX:-UseSerialGCÂ Â Â Â Â Â Â Â Â Â Â Â Â Use serial garbage collection. (Introduced in 5.0).
-XX:-PrintGCÂ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Print messages at garbage collection.
-XX:-ParallelGCThreads   Sets the number of garbage collection of threads in the young and old parallel garbage collectors. The default value varies with the platform on which the JVM is running.