On Tuesday, 8 November 2016 at 07:39:12 UTC, Era Scarecrow wrote:
On Tuesday, 8 November 2016 at 06:04:59 UTC, thedeemon wrote:
On Tuesday, 8 November 2016 at 05:36:22 UTC, Era Scarecrow wrote:

Hmmm.. I had the impression that if something was referenced by another object, then it couldn't be collected,

Another *live* object, I.e. reachable from globals and stack. If you have a big tree and it becomes unreachable (you only had a pointer to its root and you nulled it), then this whole tree becomes garbage, and its nodes and leafs will be collected in unpredictable order, with destructors being run in unpredictable order, even when these dead nodes reference each other.

And I can't help but hope it would start at the largest/base object and work it's way up. Or the largest object and then work it's way down. Alright...

One of the reasons it is not specified is that very often the hierarchy is not a simple tree, but a graph with possibly many cycles. As a matter of fact, very often child nodes have pointers to parent nodes, so that what is logically a tree is practically a graph with lots of cycles. So it is not possible to identify a root object which does not have incoming dead pointers, and no guarantee can be provided.

Reply via email to