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

Tim Peters report at bugs.python.org
Fri Jul 24 16:48:32 EDT 2020


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

I see no evidence of a bug here. To the contrary, the output proves that __del__ methods are getting called all along. And if garbage weren't being collected, after allocating a million objects each with its own megabyte string object, memory use at the end would be a terabyte, not a comparatively measly ;-) gigabyte

Note that Python's cyclic gc is NOT asynchronous. It only runs when you call it directly, or when an internal count of allocations exceeds an internal count of deallocations. When your loop ends, your output shows that 940 A and B objects remain to be collected, spread across some number of the gc's "generations". That's where your gigabyte lives (about a thousand A objects each with its own megabyte of string data). It will remain in use until gc is forced to run again. But 99.9% of the A objects have already been collected.

----------
nosy: +tim.peters

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


More information about the Python-bugs-list mailing list