Explain Garbage collection mechanism in Java.1. Garbage collection is also called automatic memory management as JVM automatically removes the unused variables/objects (value is null) from the memory.
2. The purpose of garbage collection is to identify and remove objects that are no longer needed by a program.
3. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used.
4. Every class inherits finalize() method from java.lang.Object, the finalize() method is called by garbage collector when it determines no more references to the object exists.
5. Calling System.gc() and Runtime.gc(), JVM tries to recycle the unused objects
6. No guarantee that Garbage collection will start immediately upon request of System.gc().