Garbage Collection in Java

Automatic Garbage Collection

Automatic garbage collection is the process of identifying the used and unused objects in heap memory and deleting the unused objects to reclaim memory. 

  • Used Object / Referenced Object : The object which is referenced by some part of the program.
  • Unused object / Unreferenced object : The object which is no longer referenced by any part of the program. So it can be deleted to reclaim memory.

In a programming language like C, allocating and deallocating memory is a manual process. In Java, process of deallocating memory is handled automatically by the garbage collector.

A general Garbage Collection implementation involves three steps:

  1. Marking : To identify and mark used & unused memory
  2. Sweeping/Deleting
  3. Compaction

REFERENCES

  1. https://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html
  2. https://stackify.com/what-is-java-garbage-collection
  3. https://www.freecodecamp.org/news/garbage-collection-in-java-what-is-gc-and-how-it-works-in-the-jvm/


Post a Comment

0 Comments