Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

On gc

 
amit bhadre
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how gc() method will come to know that Object is no longer usable.That is how it identifies tha objects in jvm, which mechanism is used?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has nothing to do with Threads; moving to Java in General (Beginner).
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many ways to implement GC, but most modern implementations use some variation of the "mark and sweep" algorithm. Basically, the collector starts from all static member variables and the stack frames of all threads. It "marks" every object to which it finds a reference. Then it looks at the member variables of all those objects, and marks the referenced objects. And then the members of those, etc. Eventually, all reachable objects are marked. Then the GC looks through memory for unmarked objects; those are the unreachable ones that can be collected.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic