nascheme · GitHub

Bug report

Bug description:

The HAMT iterator types declare Py_TPFLAGS_HAVE_GC and implement tp_traverse, tp_clear and a tp_dealloc that untracks, but hamt_baseiter_new() never called PyObject_GC_Track(). A reference cycle running through an iterator -- iterator -> HAMT -> object -> iterator -- was therefore invisible to the collector and never freed. Because a contextvars.Context is backed by a HAMT that pins every object in it, one leaked iterator leaks the whole context.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Read the original on github.com ↗