aspose file tools*
The moose likes Beginning Java and the fly likes On gc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "On gc" Watch "On gc" New topic
Author

On gc

amit bhadre
Ranch Hand

Joined: Jan 23, 2006
Posts: 124
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?


Thanks advance who ever answers this question.


regards
amit bhadre
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

This has nothing to do with Threads; moving to Java in General (Beginner).


[Jess in Action][AskingGoodQuestions]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: On gc
 
Similar Threads
Garbage collection
Doubt Garbage Collection
finalize()
Garbage Collection
Garbage Collection - P274 Kathy Sierra