Garbage collection algorithms is a very well-studied area. Like Bill said, which garbage-collection algorithm a JVM uses is upto the implementor of the JVM. The JLS only says that unreferenced objects
are eligible for garbage-collection. It is
not even compulsory for a JVM to have a garbage collector!
There are basically 2 approaches: reference counting, and tracing algorithms. The earliest implementations of the JVM by Sun used reference counting, but it is no longer used. The current JVM's probably use a sophisticated tracing algorithm. Mark & sweep is the simplest form of a tracing gc algorithm. Also the garbage-collector will have certain techniques for combating heap fragmentation too.
Originally posted by Pravin Panicker:
Hi EveryBody,
Does java use a mark and sweep algorithm for Garbage Collection?
Since the Garbage Collector calls finalize on unreferenced objects and collects them only on the subsequent round(s) ,is this not mark 'n sweep ?
Thanks and Regards,
-- Pravin Panicker