Title: HAMT iterators are not tracked by GC and can leak · Issue #155515 · python/cpython · GitHub
Open Graph Title: HAMT iterators are not tracked by GC and can leak · Issue #155515 · python/cpython
X Title: HAMT iterators are not tracked by GC and can leak · Issue #155515 · python/cpython
Description: 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 throug...
Open Graph Description: 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_T...
X Description: 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_T...
Opengraph URL: https://github.com/python/cpython/issues/155515
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"HAMT iterators are not tracked by GC and can leak","articleBody":"# Bug report\n\n### Bug description:\n\nThe 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.\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-155517\n* gh-155697\n* gh-155698\n* gh-155918\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/nascheme","@type":"Person","name":"nascheme"},"datePublished":"2026-08-10T19:33:28Z","url":"https://github.com/python/cpython/issues/155515"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:58bd343f-c7d0-d578-31a7-7da4368d5fee |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C360:3DCD28:1E3098A:27D8177:6B0231C4 |
| html-safe-nonce | a2721f8532d388314fa32127bdd20c81e95490cddc9e9e2adebc9eca5ccc68e1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMzYwOjNEQ0QyODoxRTMwOThBOjI3RDgxNzc6NkIwMjMxQzQiLCJ2aXNpdG9yX2lkIjoiNTc1Mzc5NzA3MDY3MDY3MjMyNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4c9152707a2c04df2569a7388824ceba339b00c8b215bede298ad3b5e67902ff |
| hovercard-subject-tag | issue:5113672874 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/155515/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7a8bd235549f7889eed3d5367a8384d9389735645860c085f4b3dd2c4c13d4f9/python/cpython/issues/155515 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7a8bd235549f7889eed3d5367a8384d9389735645860c085f4b3dd2c4c13d4f9/python/cpython/issues/155515 |
| og:image:alt | 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_T... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nascheme |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width