Tim Peters <t...@python.org> added the comment:
A simple (finalizer-only) example of what an SCC-based DAG topsort ordering would accomplish: import gc class C: def __init__(self, val): self.val = val def __del__(self): print("finalizing", self.val) c, b, a = map(C, "cba") a.next = b b.next = c #a.loop = a del c, b, a gc.collect() That finalizes in the order a, b, c. Refcount semantics force that. But, uncomment the "a.loop = a" line, and the order changes to c, b, a. They all look exactly the same to gc, so it runs finalizers in the order they happen to appear in the list gc is crawling over. A DAG topsort ordering would force a, b, c order again. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue40312> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com