What is GC in linux?

  • GC contains 3 phases — marking, deletion, copying/compaction.
    - Marking: marks everything either as live (referenced) objects, unreferenced objects or available memory space.
    - Deletion: Unreferenced objects are deleted.
    - Compaction: Remaining objects are compacted.
  • Objects are aging through these 3 phases.
  • GC can cause performance issues. So, properly using/knowing garbage collection is import to manage environment.
  • GC perfomance Concerns
    - Memory leaks: Because GC only stops unreferenced objects, memory can be fulled with referenced objects that is no longer in used.
    - Continuous “Stop the World” Events: For executing GC, all threads in the JVM are stopped. It is expected there is low impact but this can cause performance issue.
    - CPU usage: Continuous “Stop the World” can cause a spike in CPU usage.
  • How does GC work?
    When Objects allocated in heap → Places in Eden space → marked (referenced, unreferenced) → deletion → compacted → … (Loop)
    : https://www.youtube.com/watch?v=DQgwQYjjyuA&t=30s
  • There are few different kind of Java GC.
    - G1 Collector(Default GC in Java 9)
    - CMS Collector (Concurrent Mark Sweep)
    - Serial Collector
    - Parallel Collector
  • Improving GC performance
    - Adjust the heap sizes of young and old generations.
    - Reduce the rate of object allocation and promotion.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store