This week's book giveaway is in the Java in General forum.
We're giving away four copies of Java by Comparison (eBook) and have Simon Harrer, Jörg Lenhard, Linus Dietz on-line!
See this thread for details.
Win a copy of Java by Comparison (eBook) this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How Garbage Collector works?  RSS feed

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
author
Sheriff
Posts: 23381
128
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
He loves you so much! And I'm baking the cake! I'm going to put this tiny ad in the cake:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!