• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How Garbage Collector works?

 
Jalli Venkat
Greenhorn
Posts: 27
  • 0
  • 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?
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic