René's URL Explorer Experiment


Title: Free-threaded build never returns freed memory to the OS on macOS, even with gc.collect() and MIMALLOC_PURGE_DELAY=0 · Issue #158972 · python/cpython · GitHub

Open Graph Title: Free-threaded build never returns freed memory to the OS on macOS, even with gc.collect() and MIMALLOC_PURGE_DELAY=0 · Issue #158972 · python/cpython

X Title: Free-threaded build never returns freed memory to the OS on macOS, even with gc.collect() and MIMALLOC_PURGE_DELAY=0 · Issue #158972 · python/cpython

Description: Bug report On the free-threaded build, memory freed after a large transient allocation is never returned to the OS. RSS stays at the peak permanently. The free-threading HOWTO says gc.collect() releases memory held by QSBR, and that MIMA...

Open Graph Description: Bug report On the free-threaded build, memory freed after a large transient allocation is never returned to the OS. RSS stays at the peak permanently. The free-threading HOWTO says gc.collect() rel...

X Description: Bug report On the free-threaded build, memory freed after a large transient allocation is never returned to the OS. RSS stays at the peak permanently. The free-threading HOWTO says gc.collect() rel...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Free-threaded build never returns freed memory to the OS on macOS, even with gc.collect() and MIMALLOC_PURGE_DELAY=0","articleBody":"### Bug report\n\nOn the free-threaded build, memory freed after a large transient allocation is never returned to the OS. RSS stays at the peak permanently. The free-threading HOWTO says gc.collect() releases memory held by QSBR, and that MIMALLOC_PURGE_DELAY=0 reduces mimalloc's delay before returning freed memory to the OS. On macOS neither changes anything and RSS does not drop at all.\n\nThe default (GIL) build of the same version returns almost everything.\n\nReproduction script:\n```python\nimport gc\nimport os\nimport subprocess\nimport sys\nimport time\n\n\ndef rss_mib():\n    out = subprocess.run([\"ps\", \"-o\", \"rss=\", \"-p\", str(os.getpid())], capture_output=True, text=True)\n    return int(out.stdout) // 1024\n\n\nfree_threaded = not sys._is_gil_enabled()\nprint(sys.version.split()[0], \"free-threaded\" if free_threaded else \"default (GIL)\")\nprint(f\"start                    {rss_mib():6d} MiB\")\n\njunk = [[i] * 30 for i in range(4_000_000)]\nprint(f\"after allocating         {rss_mib():6d} MiB\")\n\ndel junk\ngc.collect()\ngc.collect()\nprint(f\"after del + gc.collect() {rss_mib():6d} MiB\")\n\ndeadline = time.monotonic() + 5\nwhile time.monotonic() \u003c deadline:\n    [str(i) for i in range(20_000)]\ngc.collect()\nprint(f\"after 5s more activity   {rss_mib():6d} MiB\")\n```\n\nOutput from macOS 26.7.1, arm64:\n```\n$ PYTHON_GIL=0 python3.14t repro.py\n3.14.8 free-threaded\nstart                        21 MiB\nafter allocating           1466 MiB\nafter del + gc.collect()   1466 MiB\nafter 5s more activity     1466 MiB\n\n$ MIMALLOC_PURGE_DELAY=0 PYTHON_GIL=0 python3.14t repro.py\n3.14.8 free-threaded\nstart                        21 MiB\nafter allocating           1466 MiB\nafter del + gc.collect()   1466 MiB\nafter 5s more activity     1466 MiB\n\n$ python3.14 repro.py\n3.14.8 default (GIL)\nstart                        16 MiB\nafter allocating           1335 MiB\nafter del + gc.collect()     50 MiB\nafter 5s more activity       51 MiB\n```\n\nAs far as I can tell, its the same behaviour on 3.13.16t and 3.15.0rc2t (measured with vmmap though). on the 3.15 version, MIMALLOC_PURGE_DELAY=0 makes no difference as well. This whole issue could be related to https://github.com/microsoft/mimalloc/issues/1422 but im not entirely certain.\n\nI have tried a few mimalloc options as well with no luck. It also doesn't seem to matter if the allocation and free-ing happen on the main thread or a worker thread that exits or a worker thread that stays alive for a long period.\n\nThis seems to peak out depending on what you are doing on the threads rather than leaking forever in an unbounded way, if I do a repeated 0.5GBish allocate-then-free several times (on the same or a new one every time) then RSS stays approximately flat at whatever its first peak hit.\n\n`vmmap` is reporting the retained memory as belonging to IOAccelerator but I believe that is because the `mi_options_os_tag` defaults to 100 which maps to IOAccelerator on mac. It may be worth choosing a different value for this as it originally caused me to misdiagnose this as a GPU memory leak.\n\n### CPython versions tested on:\n\n3.14, 3.15, 3.13\n\n### Operating systems tested on:\n\nmacOS\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-160150\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/dotdandotunderscore","@type":"Person","name":"dotdandotunderscore"},"datePublished":"2026-10-07T15:32:09Z","url":"https://github.com/python/cpython/issues/158972"}

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:26d1bafe-9698-3b3e-79ba-a633eed12d00
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA9F0:215B92:34D60FD:465E0EE:6B020194
html-safe-nonce3eb0c5537965a22009100f643d676224f490fbad500d5abc36079eed1b93a540
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOUYwOjIxNUI5MjozNEQ2MEZEOjQ2NUUwRUU6NkIwMjAxOTQiLCJ2aXNpdG9yX2lkIjoiODY1ODQ4NTQyMzMyMzIyMTk3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac1d9fb83c62bac5a7592ffeca427307899df222224df5452ab80f082d98f55cb0
hovercard-subject-tagissue:5747551102
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/158972/issue_layout
twitter:imagehttps://opengraph.githubassets.com/ad29e2d90ccd17e728b36eb6e63e4a479a89748088733fce0ae839d649d7bf71/python/cpython/issues/158972
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/ad29e2d90ccd17e728b36eb6e63e4a479a89748088733fce0ae839d649d7bf71/python/cpython/issues/158972
og:image:altBug report On the free-threaded build, memory freed after a large transient allocation is never returned to the OS. RSS stays at the peak permanently. The free-threading HOWTO says gc.collect() rel...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamedotdandotunderscore
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/158972#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F158972
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%2F158972
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/158972
Reloadhttps://github.com/python/cpython/issues/158972
Reloadhttps://github.com/python/cpython/issues/158972
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/158972
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/158972
Free-threaded build never returns freed memory to the OS on macOS, even with gc.collect() and MIMALLOC_PURGE_DELAY=0https://github.com/python/cpython/issues/158972#top
https://github.com/mpage
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
sprinthttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22sprint%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/dotdandotunderscore
dotdandotunderscorehttps://github.com/dotdandotunderscore
on Oct 7, 2026https://github.com/python/cpython/issues/158972#issue-5747551102
microsoft/mimalloc#1422https://github.com/microsoft/mimalloc/issues/1422
gh-158972: Drain each thread's page list during GC #160150https://github.com/python/cpython/pull/160150
dotdandotunderscorehttps://github.com/dotdandotunderscore
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
on Oct 7, 2026https://github.com/python/cpython/issues/158972#event-32703066006
https://github.com/picnixz
picnixzhttps://github.com/picnixz
on Oct 7, 2026https://github.com/python/cpython/issues/158972#issuecomment-6042764192
https://microsoft.github.io/mimalloc/environment.htmlhttps://microsoft.github.io/mimalloc/environment.html
@colesburyhttps://github.com/colesbury
picnixzhttps://github.com/picnixz
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
on Oct 7, 2026https://github.com/python/cpython/issues/158972#event-32709703227
https://github.com/dotdandotunderscore
dotdandotunderscorehttps://github.com/dotdandotunderscore
on Oct 8, 2026https://github.com/python/cpython/issues/158972#issuecomment-6054964565
kevinprimeraquecreo-stackhttps://github.com/kevinprimeraquecreo-stack
Project_VKhttps://github.com/users/kevinprimeraquecreo-stack/projects/1
on Oct 18, 2026https://github.com/python/cpython/issues/158972#event-33592149809
github-project-automationhttps://github.com/apps/github-project-automation
Project_VKhttps://github.com/users/kevinprimeraquecreo-stack/projects/1
on Oct 18, 2026https://github.com/python/cpython/issues/158972
kevinprimeraquecreo-stackhttps://github.com/kevinprimeraquecreo-stack
Project_VKhttps://github.com/users/kevinprimeraquecreo-stack/projects/1
on Oct 18, 2026https://github.com/python/cpython/issues/158972#event-33592178722
mpagehttps://github.com/mpage
on Oct 20, 2026https://github.com/python/cpython/issues/158972#event-33777765599
https://github.com/mpage
mpagehttps://github.com/mpage
on Oct 21, 2026https://github.com/python/cpython/issues/158972#issuecomment-6307125244
Freed arena memory stays resident in an idle process; no targeted or size-threshold eager purge short of process-wide purge_delay=0 microsoft/mimalloc#1422https://github.com/microsoft/mimalloc/issues/1422
Apple friendly way to madvice on commit/decommit: MADV_FREE_REUSABLE/MADV_FREE_REUSE microsoft/mimalloc#1097https://github.com/microsoft/mimalloc/pull/1097
Upgrade mimalloc version from 2.1.2 to 2.5.2 #159111https://github.com/python/cpython/issues/159111
https://github.com/corona10
corona10https://github.com/corona10
on Oct 21, 2026https://github.com/python/cpython/issues/158972#issuecomment-6329013676
@DinoVhttps://github.com/DinoV
corona10https://github.com/corona10
sprinthttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22sprint%22
on Oct 22, 2026https://github.com/python/cpython/issues/158972#event-33973991703
github-project-automationhttps://github.com/apps/github-project-automation
Sprinthttps://github.com/orgs/python/projects/32
on Oct 22, 2026https://github.com/python/cpython/issues/158972#event-33973997933
github-project-automationhttps://github.com/apps/github-project-automation
Sprinthttps://github.com/orgs/python/projects/32
on Oct 22, 2026https://github.com/python/cpython/issues/158972
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/158972
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/158972
mpagehttps://github.com/mpage
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
sprinthttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22sprint%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
Sprinthttps://github.com/orgs/python/projects/32
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.