René's URL Explorer Experiment


Title: Free threading memory leak · Issue #145615 · python/cpython · GitHub

Open Graph Title: Free threading memory leak · Issue #145615 · python/cpython

X Title: Free threading memory leak · Issue #145615 · python/cpython

Description: This bug was originally found by a colleague. Memory usage (RSS) keeps increasing even though allocated blocks stays essentially constant. Self contained reproducer below: import gc import sys import os import concurrent.futures def get_...

Open Graph Description: This bug was originally found by a colleague. Memory usage (RSS) keeps increasing even though allocated blocks stays essentially constant. Self contained reproducer below: import gc import sys impo...

X Description: This bug was originally found by a colleague. Memory usage (RSS) keeps increasing even though allocated blocks stays essentially constant. Self contained reproducer below: import gc import sys impo...

Opengraph URL: https://github.com/python/cpython/issues/145615

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Free threading memory leak","articleBody":"This bug was originally found by a colleague. Memory usage (RSS) keeps increasing even though allocated blocks stays essentially constant. Self contained reproducer below:\n\n```python\nimport gc\nimport sys\nimport os\nimport concurrent.futures\n\ndef get_rss_mb():\n    with open(\"/proc/self/statm\") as f:\n        return int(f.read().split()[1]) * os.sysconf(\"SC_PAGE_SIZE\") / (1024 * 1024)\n\ndef work(_):\n    return [bytearray(64) for _ in range(4000)]\n\n\nNUM_ITERATIONS = int(sys.argv[1]) if len(sys.argv) > 1 else 20\n\npool = concurrent.futures.ThreadPoolExecutor(max_workers=4)\nfor i in range(NUM_ITERATIONS):\n    futures = [pool.submit(work, j) for j in range(100)]\n    results = [f.result() for f in futures]\n    del futures, results  # free worker-allocated objects on main thread\n    gc.collect()\n    gc.collect()\n    blocks = sys.getallocatedblocks()\n    print(f\"iter {i:3d}: RSS={get_rss_mb():7.1f} MB {blocks=}\")\n\npool.shutdown()\nprint(f\"after shutdown: RSS={get_rss_mb():7.1f} MB\")\n```\n\nThe problem is that we end up having orphaned mimalloc pages in the full queue, even though those pages have available blocks or are completely empty. They're \"leaked\" until the thread exits.\n\n**NOTE**: The bugs are limited out our mimalloc modifications. They're not in upstream mimalloc.\n\nI think there are at least two underlying bugs here:\n\n1) `_PyMem_mi_page_maybe_free` leaves empty pages in the full page queue. This bug can happen when a page goes from \"full\" to \"all free\".\n2) `_mi_page_free_collect` calls `_PyMem_mi_page_clear_qsbr` if `page->local_free != NULL`. This can get erroneously triggered even the by traversing heaps. We only want to clear the page QSBR counter when it becomes empty again.\n\nAdditionally, `_PyMem_mi_page_maybe_free` can insert pages into the wrong mimalloc list. `_PyMem_mi_page_maybe_free` inserts the page into the *current thread's* list. However, during GC and other stop-the-world pauses, we may traverse the heaps of other threads. That traversal does some processing of free lists, which can end up calling `_PyMem_mi_page_maybe_free`. In that case, we should insert the page into the *owning thread's*  list, **not** the current thread's list. Otherwise, we can end up with a data race later on.\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-145626\n* gh-145691\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/colesbury","@type":"Person","name":"colesbury"},"datePublished":"2026-03-07T01:34:26Z","url":"https://github.com/python/cpython/issues/145615"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:8eeef6e7-7063-a80f-b1be-ee0c1e89f258
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC894:2270F4:34F49BE:463C20E:6B01FB5E
html-safe-nonceb915681985c5919135d3bba1c026bbfa06bbe68710412bfa5a3866504049f292
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDODk0OjIyNzBGNDozNEY0OUJFOjQ2M0MyMEU6NkIwMUZCNUUiLCJ2aXNpdG9yX2lkIjoiMTk1MDk0MDkzODM5ODQ2NDg2MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac2d98f53c5cf6f5887ce0df56597607870101f4b5223a04b797b9e8a539f001d2
hovercard-subject-tagissue:4036931195
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/145615/issue_layout
twitter:imagehttps://opengraph.githubassets.com/97c6f60d9710022da61cd037f9284372456a2f7d9bb3d0b86d2a53b0ea878bc3/python/cpython/issues/145615
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/97c6f60d9710022da61cd037f9284372456a2f7d9bb3d0b86d2a53b0ea878bc3/python/cpython/issues/145615
og:image:altThis bug was originally found by a colleague. Memory usage (RSS) keeps increasing even though allocated blocks stays essentially constant. Self contained reproducer below: import gc import sys impo...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamecolesbury
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/145615#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F145615
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F145615
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/145615
Reloadhttps://github.com/python/cpython/issues/145615
Reloadhttps://github.com/python/cpython/issues/145615
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/145615
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/145615
Free threading memory leakhttps://github.com/python/cpython/issues/145615#top
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/colesbury
colesburyhttps://github.com/colesbury
on Mar 7, 2026https://github.com/python/cpython/issues/145615#issue-4036931195
gh-145615: Fix mimalloc page leak in the free-threaded build #145626https://github.com/python/cpython/pull/145626
[3.14] gh-145615: Fix mimalloc page leak in the free-threaded build (gh-145626) #145691https://github.com/python/cpython/pull/145691
colesburyhttps://github.com/colesbury
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
on Mar 7, 2026https://github.com/python/cpython/issues/145615#event-23349292207
https://github.com/Krishna-web-hub
Krishna-web-hubhttps://github.com/Krishna-web-hub
on Mar 7, 2026https://github.com/python/cpython/issues/145615#issuecomment-4016098008
@colesburyhttps://github.com/colesbury
colesburyhttps://github.com/colesbury
on Mar 7, 2026https://github.com/python/cpython/issues/145615#event-23360277252
pythongh-145615: Fix mimalloc page leak in the free-threaded buildhttps://github.com/colesbury/cpython/commit/218b6bfeb600f2b8d9bbcbe5756260deb05c016a
pythongh-145615https://github.com/python/cpython/issues/145615
218b6bfhttps://github.com/colesbury/cpython/commit/218b6bfeb600f2b8d9bbcbe5756260deb05c016a
colesburyhttps://github.com/colesbury
_PyMem_mi_page_maybe_free may insert pages into wrong thread's list #145614https://github.com/python/cpython/issues/145614
on Mar 7, 2026https://github.com/python/cpython/issues/145615#event-23360315481
colesburyhttps://github.com/colesbury
on Mar 9, 2026https://github.com/python/cpython/issues/145615#event-23404055134
gh-145615: Fix mimalloc page leak in the free-threaded build (gh-145626)https://github.com/python/cpython/commit/d76df75f51e662fd15ebe00e107058841de94860
gh-145615https://github.com/python/cpython/issues/145615
gh-145626https://github.com/python/cpython/pull/145626
d76df75https://github.com/python/cpython/commit/d76df75f51e662fd15ebe00e107058841de94860
miss-islingtonhttps://github.com/miss-islington
on Mar 9, 2026https://github.com/python/cpython/issues/145615#event-23404058084
pythongh-145615: Fix mimalloc page leak in the free-threaded build (p…https://github.com/miss-islington/cpython/commit/2a3a642efcfd7d1b567e2d099fdde4442f23cccf
pythongh-145615https://github.com/python/cpython/issues/145615
p…https://github.com/python/cpython/pull/145626
2a3a642https://github.com/miss-islington/cpython/commit/2a3a642efcfd7d1b567e2d099fdde4442f23cccf
colesburyhttps://github.com/colesbury
on Mar 9, 2026https://github.com/python/cpython/issues/145615#event-23405532319
[3.14] gh-145615: Fix mimalloc page leak in the free-threaded build (g…https://github.com/python/cpython/commit/ba1ea3a85a13efb18baef54e63ed04d71ad84171
gh-145615https://github.com/python/cpython/issues/145615
g…https://github.com/python/cpython/pull/145626
ba1ea3ahttps://github.com/python/cpython/commit/ba1ea3a85a13efb18baef54e63ed04d71ad84171
colesburyhttps://github.com/colesbury
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Mar 9, 2026https://github.com/python/cpython/issues/145615#event-23405538483
ljfphttps://github.com/ljfp
on Apr 25, 2026https://github.com/python/cpython/issues/145615#event-24868324321
pythongh-145615: Fix mimalloc page leak in the free-threaded build (p…https://github.com/ljfp/cpython/commit/581c0ab64329745110956f78ee768195c35d091b
pythongh-145615https://github.com/python/cpython/issues/145615
p…https://github.com/python/cpython/pull/145626
581c0abhttps://github.com/ljfp/cpython/commit/581c0ab64329745110956f78ee768195c35d091b
corona10https://github.com/corona10
on Oct 10, 2026https://github.com/python/cpython/issues/145615#event-32938772617
Re-apply CPython-specific changes to mimalloc v2.5.2https://github.com/corona10/cpython/commit/fa3a143e1246e55a659a1f2084138263f0e87ef4
fa3a143https://github.com/corona10/cpython/commit/fa3a143e1246e55a659a1f2084138263f0e87ef4
Re-apply CPython-specific changes to mimalloc v2.5.2https://github.com/corona10/cpython/commit/836dced561ffdbc89e2cd33594d20c23953786ac
836dcedhttps://github.com/corona10/cpython/commit/836dced561ffdbc89e2cd33594d20c23953786ac
corona10https://github.com/corona10
on Oct 22, 2026https://github.com/python/cpython/issues/145615#event-33902120787
gh-159111: Update vendored mimalloc to v2.5.2 (gh-159112)https://github.com/python/cpython/commit/aff7a2e23bd6ed68fa15c1ceda94a2fdd7f8cf7f
gh-159111https://github.com/python/cpython/issues/159111
gh-159112https://github.com/python/cpython/pull/159112
aff7a2ehttps://github.com/python/cpython/commit/aff7a2e23bd6ed68fa15c1ceda94a2fdd7f8cf7f
[3.15] pythongh-159111: Update vendored mimalloc to v2.5.2 (pythongh-…https://github.com/corona10/cpython/commit/265f0fb3011cf87cb659135452ad09bc2d406e3a
pythongh-159111https://github.com/python/cpython/issues/159111
pythongh-…https://github.com/python/cpython/pull/159112
265f0fbhttps://github.com/corona10/cpython/commit/265f0fb3011cf87cb659135452ad09bc2d406e3a
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/145615
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/145615
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.