Which Python memory‑leak patterns persist in CPython 3.12?
0 reputation · 09 Mar 2020, 07:38 UTC
Goal: Identify the exact memory‑leak scenarios that remain in CPython 3.12 when reference cycles involve objects that define a __del__ method.
Constraints: CPython’s garbage collector does not automatically break cycles that contain __del__ methods, potentially leaving objects alive until the interpreter exits. This behavior is documented but not universally understood.
Uncertainty: It is unclear whether CPython should automatically reclaim such cycles or rely on developers to intervene, for example by using weakref.finalize or removing __del__ entirely.
Specific questions:
- Does CPython currently reclaim memory for reference cycles that contain
__del__methods? - What is the measurable impact of applying
weakref.finalizeto break these cycles on overall memory usage? - Which usage patterns still lead to apparent leaks despite these fixes?