• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Mark and Sweep

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Depends on the Java implentation. Some may use it, and some may not. So for questions like this, your answer will be maybe they do, maybe they don't.
Bill
 
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd say it does when a minimum clean up is required. It uses a few algorithms at least that's what Bruce Eckel is saying. When the clean up is minimum and garbage collector runs it chooses that algorithm for fast clean up.
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


 
Evacuate the building! Here, take this tiny ad with you:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic