Title: Memory held for too long by the BRC queue while the owning thread is detached · Issue #157838 · python/cpython · GitHub
Open Graph Title: Memory held for too long by the BRC queue while the owning thread is detached · Issue #157838 · python/cpython
X Title: Memory held for too long by the BRC queue while the owning thread is detached · Issue #157838 · python/cpython
Description: On the free-threaded build, when a non-owner thread decrefs an object and ob_ref_shared drops to zero, the object is queued for its owning thread and is only freed when that thread next runs Python code. If the owner stays detached for a...
Open Graph Description: On the free-threaded build, when a non-owner thread decrefs an object and ob_ref_shared drops to zero, the object is queued for its owning thread and is only freed when that thread next runs Python...
X Description: On the free-threaded build, when a non-owner thread decrefs an object and ob_ref_shared drops to zero, the object is queued for its owning thread and is only freed when that thread next runs Python...
Opengraph URL: https://github.com/python/cpython/issues/157838
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Memory held for too long by the BRC queue while the owning thread is detached","articleBody":"On the free-threaded build, when a non-owner thread decrefs an object and ob_ref_shared drops to zero, the object is queued for its owning thread and is only freed when that thread next runs Python code. If the owner stays detached for a long time — blocked on a lock, in a syscall, waiting on a pipe — the queued objects stay alive for as long as the owner is blocked. The GC drains the queue, but if the objects holds large amounts of memory then it is ineffective. \n\nThis was reported in [Py314t uses 2× memory](https://discuss.python.org/t/py314t-uses-2x-memory/108941): a PyTorch training run uses 10GB on 3.14 and 20GB on 3.14t. The objects are large tensors enqueued on a multiprocessing.Queue, whose feeder thread does the cross-thread decref while the owner sits detached.\n\n\nI propose to let the queueing thread do the merge itself. When it tries to queue a object of detached owner, it moves the owner from detached to suspended (the same transition stop-the-world uses), merges the refcounts, resumes the owner, and deallocates whatever reached zero outside the bucket mutex. \n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-157839\n* gh-158011\n* gh-158012\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/kumaraditya303","@type":"Person","name":"kumaraditya303"},"datePublished":"2026-09-20T05:09:32Z","url":"https://github.com/python/cpython/issues/157838"}
| 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:64efa4f8-286f-1684-f40c-f13157aa98ad |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A66E:6365:3500EEC:46B279C:6B0207A1 |
| html-safe-nonce | d5dbba30b56f3f88a63586b7d88684d7c59113f5d6016ed43344089012050dc5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNjZFOjYzNjU6MzUwMEVFQzo0NkIyNzlDOjZCMDIwN0ExIiwidmlzaXRvcl9pZCI6IjE5MTY5MTkzOTQzNDUyODk2MzMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 04398897f39c5b2ef22a51fbded9feb01a40af4f2e0320f6a1e2453b57a02d9f |
| hovercard-subject-tag | issue:5515910851 |
| 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/157838/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4aacff4b16c050fa1ba24aeb8c940e67ba7248acf0abd4cc74f2798084e36a5c/python/cpython/issues/157838 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4aacff4b16c050fa1ba24aeb8c940e67ba7248acf0abd4cc74f2798084e36a5c/python/cpython/issues/157838 |
| og:image:alt | On the free-threaded build, when a non-owner thread decrefs an object and ob_ref_shared drops to zero, the object is queued for its owning thread and is only freed when that thread next runs Python... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kumaraditya303 |
| 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