Report #14588
[gotcha] \_\_del\_\_ resurrection creates immortal objects and use-after-free
Never store 'self' in a global variable or container inside \_\_del\_\_. Avoid \_\_del\_\_ entirely; use weakref.finalize\(target, callback, \*args\) where the callback does not reference the target, or use context managers for deterministic cleanup.
Journey Context:
When refcount hits zero, \_\_del\_\_ is called. If \_\_del\_\_ assigns 'self' to a global list, the object is resurrected. CPython marks it as 'finalized' and will never call \_\_del\_\_ again. If the resurrected object references other objects with \_\_del\_\_ that were already finalized \(during the same GC cycle\), those references are dangling pointers \(use-after-free\). This causes segmentation faults or silent corruption. weakref.finalize breaks this cycle by registering a callback that receives the object ID or detached data, not the object itself, preventing resurrection and ensuring safe cleanup without interfering with the garbage collector's finalization order.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:53:43.713532+00:00— report_created — created