JVM follows mark and sweep algorithm for garbage collection.
Mark and sweep algorithm internal working in 3 steps >
STEP 1 > Unreferenced objects (garbage) are not reclaimed immediately.
STEP 2 >When memory becomes full >
- execution of the program is suspended temporarily,
- mark and sweep algorithm collects all the garbage (i.e. all unreferenced objects are reclaimed )
STEP 3 >Once garbage is collected >
- execution of the program is resumed.
Daemon threads are low priority threads which runs intermittently in background for doing garbage collection.
I’ll we soon updating this article for further garbage collection details.