Garbage Collection Quick Guide

Present you the Garbage Collection Quick Guide:

Garbage Collection Basics:

  • Garbage Collector is a Java program
  • Garbage Collection is a method of reclaiming unused heap memory.
  • In garbage collection, neither the explicit deletion of the memory happens nor the memory is returned to the operating system.

Garbage Collection Activities:

  1. Mark: To mark the generation of the object. 
  2. Delete/Sweep: To delete the unreachable/dead object.
  3. Compact: To compact the memory by moving around the object.

Performance Metrics targeted by GC algorithms

  1. Throughput: It denotes the number of tasks (mark-sweep-compact) performed GC per unit time. The GC algorithm which does more tasks in a short time is preferable.
  2. Latency: It represents the time taken by GC to complete. The lesser the latency; the better and quicker the GC.
  3. Memory Footprint: It shows the memory needed by a GC process to execute smoothly. If the GC algorithm takes more memory, it leads to less memory available for Heap.

Type of Garbage Collector:

  1. Serial Garbage Collector
  2. Parallel Garbage Collector
  3. CMS (Concurrent-Mark-Sweep) Garbage Collector
  4. G1 Garbage Collector
  5. Z Garbage Collector
  6. Shenandoah
  7. Azul’s C4 (Continuously Concurrent Compacting Collector)
  8. Epsilon GC
  9. IBM Metronome GC
  10. SAP GC

Comparison

GCThroughputLatencyMemory Footprint
SerialLowHighLow
ParallelHighMediumMedium
CMSMediumMediumMedium
G1HighLowMedium
ZHighVery LowHigh
ShenandoahHighVery LowHigh
C4HighVery LowHigh
EpsilonNANANA
IBM MetronomeVery HighVery LowHigh
SAP GCHighMediumHigh

Supported Java Versions

GCSupported Java Version
SerialJava 1.7 till now
ParallelJava 1.7 till now
CMSJava 1.7 till now
G1Java 1.8 till now
ZJava 9 till now
ShenandoahJava 12 till now
C4NA
EpsilonJava 15 till now
IBM MetronomeNA
SAP GCNA

Argument

GCArgument
Serial-XX:+UseSerialGC
Parallel-XX:+UseParallelGC
CMS-XX:+UseConcMarkSweepGC
G1-XX:+UseG1GC
Z-XX:+UseZGC
Shenandoah-XX:+UseShenandoahGC
C4NA
Epsilon-XX:+UseEpsilonGC
IBM MetronomeNA
SAP GCNA

Used For

GCBest For
SerialSmall-scale applications that use single-thread
ParallelLarge and Responsive Application
Batch Processing
CMSMedium to Large Scale Applications
G1Large-scale Applications
ZResponsive Applications
ShenandoahLarge and Responsive Application
C4Larger-scale Cloud Application
Epsilon(Testing Purpose) Performance and Memory Utilization Analysis
IBM MetronomeReal-time Applications
SAP GCLarge-scale SAP-based Applications

Conclusion

You read the above article i.e. ‘Garbage Collection Quick Guide’ to understand more about GC. Since the Garbage Collection is such a wide topic, it shall be elaborated in future articles.


You may be interested:

  1. Overview
  2. Memory Heap and Generation Type
  3. How does GC work?
  4. Types of GC
  5. GC Throughput
  6. GC Latency