Java garbage collection



Garbage Collection : Destroying Object in Java Programming

  1. Object is Created Using new Operator.
  2. Object gets memory inside “Heap“.
  3. In C++ After Using Object , Memory for Object gets de-allocated using delete().
  4. In Java De-allocation of Object Can be done automatically.
  5. Automatic Technique used in Java Programming Which is used to de-allocate memory is called as “Garbage Collection“.
  6. Java is Smart Enough to identify the Unused objects or Useless Objects.

Garbage Collection in Java - Destroying Object in Java Programming

Explanation :

  1. Garbage Collection is Done Automatically by JVM.
  2. As soon as compiler detects that – Object is no longer needed inside program , Garbage Collection Algorithm gets executed automatically to free up memory from the heap so that free memory may be used by other objects .
  3. Different Java Run times may have different approaches for Garbage Collection. [This is required information to understand Garbage Collection – Doing Further  R&D you may visit this]