I was reading up on garbage collection. As we know, Garbage collection collects dead object and reclaims memory. My question is, how Collector comes to know that any object is dead? what data-structure it use to keep track of live objects?
I was researching about this, I found, GC actually keep track of live objects, and marked them. every object that is not marked consider as dead. I guess, there is some thing called object-tree
is used for this purpose. but how its works I don't know.
Here are my list of questions.
new
keyword, how it affects that object-tree
?The tree is just a conceptual view on the memory heap and the references between objects. It does not exist as a separate entity.
And it's not really a tree since it can contain cycles, so calling it a graph would be more accurate. During garbage-collection it is visited in a tree-like manner (breadth-first or depth-first traversal) by following references and skipping those already visited.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments