Title: TypeAliasType can leak memory if name is a str subclass · Issue #140000 · python/cpython · GitHub
Open Graph Title: TypeAliasType can leak memory if name is a str subclass · Issue #140000 · python/cpython
X Title: TypeAliasType can leak memory if name is a str subclass · Issue #140000 · python/cpython
Description: Bug report Bug description: TypeAliasType's traverse implementation does not visit its name. This means that we can leak memory if name is passed an instance of a mutable str subclass. from typing import TypeAliasType import weakref impo...
Open Graph Description: Bug report Bug description: TypeAliasType's traverse implementation does not visit its name. This means that we can leak memory if name is passed an instance of a mutable str subclass. from typing ...
X Description: Bug report Bug description: TypeAliasType's traverse implementation does not visit its name. This means that we can leak memory if name is passed an instance of a mutable str subclass. from typ...
Opengraph URL: https://github.com/python/cpython/issues/140000
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TypeAliasType can leak memory if name is a str subclass","articleBody":"# Bug report\n\n### Bug description:\n\nTypeAliasType's traverse implementation does not visit its name. This means that we can leak memory if name is passed an instance of a mutable str subclass.\n\n```python\nfrom typing import TypeAliasType\nimport weakref\nimport gc\n\nclass S(str):\n pass\n\ndef still_alive(ref):\n obj = ref()\n if not isinstance(obj, S):\n return False\n T = obj.T\n if not isinstance(T, TypeAliasType):\n return False\n return T\n\nname = S(\"name\")\nT = TypeAliasType(name, int)\nname.T = T\nref = weakref.ref(name)\nassert still_alive(ref)\ndel name\ndel T\ngc.collect()\ngc.collect()\nassert still_alive(ref)\n\ndel ref().T\nassert not still_alive(ref)\n\n```\n\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nmacOS\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-140016\n* gh-140063\n* gh-140073\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/JelleZijlstra","@type":"Person","name":"JelleZijlstra"},"datePublished":"2025-10-12T14:45:22.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/140000/cpython/issues/140000"}
| 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:2011bd27-70b3-e826-3806-9fdb02f1c757 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8A7A:32E44A:97C860:CF4461:6A5553C7 |
| html-safe-nonce | 68435a715da72fd0028161d8311bda9f486def2d2c72f73b55f3291c41fce9f6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QTdBOjMyRTQ0QTo5N0M4NjA6Q0Y0NDYxOjZBNTU1M0M3IiwidmlzaXRvcl9pZCI6IjQyNjM3ODc5MzExNTkwNTczNTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 76b7f86b53e80fc1b94ca916d505ecfe51a73077dfa7f8ea82cb0a790b3e9260 |
| hovercard-subject-tag | issue:3507310742 |
| 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/140000/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cd8d1db353a223b5a49c558fa8c528e304ff26074af5386d68b488af1eeb0691/python/cpython/issues/140000 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cd8d1db353a223b5a49c558fa8c528e304ff26074af5386d68b488af1eeb0691/python/cpython/issues/140000 |
| og:image:alt | Bug report Bug description: TypeAliasType's traverse implementation does not visit its name. This means that we can leak memory if name is passed an instance of a mutable str subclass. from typing ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JelleZijlstra |
| hostname | github.com |
| expected-hostname | github.com |
| None | cd9eea424140838b22e9eabd53d92b5702617ddd6d76efcd3a37f08d44309ca5 |
| 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 | 3084b9f587e8f1e19803bbe0c77ac77ce3c99c5c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width