[issue41389] Garbage Collector Ignoring Some (Not All) Circular References of Identical Type

Tim Peters report at bugs.python.org
Mon Jul 27 16:58:43 EDT 2020


Tim Peters <tim at python.org> added the comment:

It's impossible for any implementation to know that cyclic trash _is_ trash without, in some way, traversing the object graph. This is expensive, so CPython (or any other language) does not incur that expense after every single decref that leaves a non-zero refcount (the one and only cheap clue that cyclic trash _may_ have just been created).

If you want/need synchronous behavior, avoid cycles. CPython's refcounting does dispose of trash the instant an object (not involved in a cycle) becomes trash. That behavior cannot be extended to cyclic trash short of (as above) running a cyclic gc pass extremely frequently.

I don't know of any language that guarantees all garbage will be collected "right away". Do you?  CPython does much more in that respect (due to primarily relying on refcounting) than most.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41389>
_______________________________________


More information about the Python-bugs-list mailing list