C # Node Tree Removing and Managing Memory

I am working on a C # application that has a tree structure. The structure consists of a list of objects Component

, and each Component

can have a list of subcomponents. My question is, if I delete the root of a tree (or subtree), does the garbage collector know to remove all sub-components and sub-components?

+3


source to share


1 answer


If the link does not point to any of the marked through any root object, then they are eligible for collection.

Put another way, if it is possible to execute any code that tries to reference this object, then it cannot be compiled; if the program can determine that it is impossible for any code executed in the future to try to access that object, then they are eligible to collect.



It doesn't matter that the objects refer to other objects that are not available.

+1


source







All Articles