what is garbage collector in java
relations withe memory
a very big topic totally skipped in the tutorial. very briefly, there's Eden space where freshly created objects go. Those still around when collection comes get promoted to a survivor space that's cleaned less often. After surviving there they can enter another survivor space or join the old generation. Collection comes when space is needed and by focusing on just a subset of objects at a time stop the world events are reduced.
In simple words
when there are no more object references, the object is removed from the heap by the garbage collector
After the execution process,the JVM inside stack area calls garbage collector which is a basic need provided by JVM. When Garbage collector settles inside stack,the JVM pops out of stack Finally the garbage collector cleans the abandoned objects and other trash that is present in the heap area.
And the abandoned objects are eligible for garbage collector