Title: Memory leak on interpreter shutdown when reference cycle exists between `structseq` type and its instance · Issue #157176 · python/cpython · GitHub
Open Graph Title: Memory leak on interpreter shutdown when reference cycle exists between `structseq` type and its instance · Issue #157176 · python/cpython
X Title: Memory leak on interpreter shutdown when reference cycle exists between `structseq` type and its instance · Issue #157176 · python/cpython
Description: Bug report Bug description: Environment Commit/Branch: main (rev: 2d9fb5f2f70b18ce9e5d9f7f76fd5ef3f118d838) OS: Linux Build flags: CC=clang CXX=clang++ LDFLAGS='-fuse-ld=lld' ./configure --with-address-sanitizer --with-undefined-behavior...
Open Graph Description: Bug report Bug description: Environment Commit/Branch: main (rev: 2d9fb5f2f70b18ce9e5d9f7f76fd5ef3f118d838) OS: Linux Build flags: CC=clang CXX=clang++ LDFLAGS='-fuse-ld=lld' ./configure --with-add...
X Description: Bug report Bug description: Environment Commit/Branch: main (rev: 2d9fb5f2f70b18ce9e5d9f7f76fd5ef3f118d838) OS: Linux Build flags: CC=clang CXX=clang++ LDFLAGS='-fuse-ld=lld' ./configure --...
Opengraph URL: https://github.com/python/cpython/issues/157176
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Memory leak on interpreter shutdown when reference cycle exists between `structseq` type and its instance","articleBody":"# Bug report\n\n### Bug description:\n\n### Environment\n- **Commit/Branch:** `main` (rev: `2d9fb5f2f70b18ce9e5d9f7f76fd5ef3f118d838`)\n- **OS:** Linux\n- **Build flags:**\n ```bash\n CC=clang CXX=clang++ LDFLAGS='-fuse-ld=lld' ./configure --with-address-sanitizer --with-undefined-behavior-sanitizer --with-pydebug && make -j$(nproc)\n ```\n\n### Steps to reproduce\nRun:\n```bash\n./python -c \"import time; t = time.gmtime(); type(t).refcyle = t;\"\n```\n\nNote: Explicitly breaking the cycle avoids the leak:\n```bash\n./python -c \"import time; t = time.gmtime(); type(t).refcyle = t; del type(t).refcyle\"\n```\n\n### Expected behavior\nThe garbage collector or interpreter finalization breaks the reference cycle during shutdown; no memory leaks reported by LeakSanitizer.\n\n### Actual behavior\nLeakSanitizer detects memory leaks (indirect leaks of the type, its dict, descriptors, and the instance):\n\n```text\n=================================================================\n==1164172==ERROR: LeakSanitizer: detected memory leaks\n\nIndirect leak of 1472 byte(s) in 1 object(s) allocated from:\n #0 0x55571ba2f651 in malloc\n #1 0x55571c0c8db7 in _PyMem_DebugRawAlloc Objects/obmalloc.c:3103:24\n #2 0x55571c130728 in _PyObject_MallocWithType Include/internal/pycore_object_alloc.h:46:17\n #3 0x55571c130728 in _PyType_AllocNoTrack Objects/typeobject.c:2495:19\n #4 0x55571c13040d in PyType_GenericAlloc Objects/typeobject.c:2526:21\n #5 0x55571c1357f9 in type_from_slots_or_spec Objects/typeobject.c:5591:30\n #6 0x55571c1148ec in _PyStructSequence_NewType Objects/structseq.c:780:28\n #7 0x55571ca6ea5c in time_exec Modules/timemodule.c:2113:31\n...\nIndirect leak of 176 byte(s) in 1 object(s) allocated from:\n #0 0x55571ba2f651 in malloc\n #1 0x55571c0c8db7 in _PyMem_DebugRawAlloc Objects/obmalloc.c:3103:24\n #2 0x55571c5d4028 in _PyObject_MallocWithType Include/internal/pycore_object_alloc.h:46:17\n #3 0x55571c5d4028 in gc_alloc Python/gc.c:2013:17\n #4 0x55571c5d4440 in _PyObject_GC_NewVar Python/gc.c:2055:25\n #5 0x55571c110247 in PyStructSequence_New Objects/structseq.c:77:11\n #6 0x55571ca69e1d in tmtotuple Modules/timemodule.c:463:19\n #7 0x55571ca67616 in time_gmtime Modules/timemodule.c:541:12\n...\nSUMMARY: AddressSanitizer: 6946 byte(s) leaked in 50 allocation(s).\n```\n\nFull LeakSanitizer output - [logs.txt](https://github.com/user-attachments/files/31956667/logs.txt)\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-157179\n* gh-158983\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/ashm-dev","@type":"Person","name":"ashm-dev"},"datePublished":"2026-09-08T12:25:31Z","url":"https://github.com/python/cpython/issues/157176"}
| 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:6703a7a4-e7c5-876e-0897-5a1399a3e31e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8320:31E99C:35EC324:47E32FA:6B020866 |
| html-safe-nonce | 2f542962b4a9f572683a7ff4206bc9bd3bbc751b64d07a48c5908515091bba8d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MzIwOjMxRTk5QzozNUVDMzI0OjQ3RTMyRkE6NkIwMjA4NjYiLCJ2aXNpdG9yX2lkIjoiNTEyMDM2ODU4MDgyMjY5ODA4NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f991dad3476e24a7c5886fe05c5f84c43feb35351672f138129fe46f3b588fa8 |
| hovercard-subject-tag | issue:5386666010 |
| 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/157176/issue_layout |
| twitter:image | https://opengraph.githubassets.com/62b52746fde87e0da95eef2a798c9046cfa0448d9fcebf7e31a439525262ee32/python/cpython/issues/157176 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/62b52746fde87e0da95eef2a798c9046cfa0448d9fcebf7e31a439525262ee32/python/cpython/issues/157176 |
| og:image:alt | Bug report Bug description: Environment Commit/Branch: main (rev: 2d9fb5f2f70b18ce9e5d9f7f76fd5ef3f118d838) OS: Linux Build flags: CC=clang CXX=clang++ LDFLAGS='-fuse-ld=lld' ./configure --with-add... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ashm-dev |
| 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