File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How  Garbage Collector works? 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 "How  Garbage Collector works?" Watch "How  Garbage Collector works?" New topic
Author

How Garbage Collector works?

Jalli Venkat
Greenhorn

Joined: Aug 10, 2006
Posts: 27
How can Garbage Collector identifies Objects which are not used by any other program? What is the internal machanism used by the Garbage Collector?
Is there any particular Condition for Garbage Collection?


venkat
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18103
    
  39

Originally posted by Jalli Venkat:
How can Garbage Collector identifies Objects which are not used by any other program? What is the internal machanism used by the Garbage Collector?
Is there any particular Condition for Garbage Collection?


There is no magic here. The GC must start from the roots (static variables, the stack for every thread, etc) and follow those references to instances. And then follow the variables in those instances to more instances. Until it has found everything that is reachable.

This is further complicated with weak references, and finalization. The condition for GC is that an instance is not reachable -- directly or indirectly -- from one of the roots.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How Garbage Collector works?
 
Similar Threads
Garbage Collection
how is garbage collector is implemented
String's and Gargage Collection
Java Questions in Interview
how to call garbage collector implicitly...