Title: [Bug]: macOS backend lacks several autorelease pools · Issue #31751 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: macOS backend lacks several autorelease pools · Issue #31751 · matplotlib/matplotlib
X Title: [Bug]: macOS backend lacks several autorelease pools · Issue #31751 · matplotlib/matplotlib
Description: Bug summary I'm investigating #31106. At the time show(PyObject* self) is called, the window in question has a -retainCount of 600+. This is due to AppKit and other macOS frameworks calling [[theWindow retain] autorelease] across several...
Open Graph Description: Bug summary I'm investigating #31106. At the time show(PyObject* self) is called, the window in question has a -retainCount of 600+. This is due to AppKit and other macOS frameworks calling [[theWi...
X Description: Bug summary I'm investigating #31106. At the time show(PyObject* self) is called, the window in question has a -retainCount of 600+. This is due to AppKit and other macOS frameworks calling [[t...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/31751
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: macOS backend lacks several autorelease pools","articleBody":"### Bug summary\n\nI'm investigating #31106.\n\nAt the time `show(PyObject* self)` is called, the window in question has a `-retainCount` of 600+. This is due to AppKit and other macOS frameworks calling `[[theWindow retain] autorelease]` across several internal methods.\n\nThe window is retained and added to the autorelease pool at the top of the stack, which is either the one set up in `wait_for_stdin()` or in `[NSApp run]`. In any case, the pool has never been drained by the time `show()` is called. Even after the user closes the window, the pool has still not been drained.\n\nGenerally, if you are calling from non-Objective-C code to Objective-C code, you need to set up an autorelease pool before crossing the boundary and release it after returning. Using an `@autoreleasepool` block makes this easy; however, it involves touching a lot of C functions inside of `_macosx.m`.\n\nI'm not experienced with Python extension modules. Is there a way to have Python automatically call a function before and after calling the C function assigned to each PyMethodDef?\n\n### Code for reproduction\n\n```Python\nimport matplotlib.pyplot as plt\n\nfor i in range(0, 4):\n plt.subplots()\n\nplt.show()\n```\n\n### Actual outcome\n\nEach `NSWindow` still has a retain count of 600+ after closing.\n\n### Expected outcome\n\nEach `NSWindow` hits a retain count of 0 on close and `-dealloc` is called.\n\n### Additional information\n\n_No response_\n\n### Operating system\n\n_No response_\n\n### Matplotlib Version\n\n0.2.0.dev54528+unknown.gf4cf12592.d20260526\n\n### Matplotlib Backend\n\n_No response_\n\n### Python version\n\n_No response_\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\nNone","author":{"url":"https://github.com/iccir","@type":"Person","name":"iccir"},"datePublished":"2026-05-26T18:40:20.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/31751/matplotlib/issues/31751"}
| 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:3d39a825-15da-6de5-cfc7-00c3d786fd3c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B938:147EC0:417CE0:56D040:6A5260E2 |
| html-safe-nonce | fc3425684219c535836d2f3d84a8a40378d769b62f5ac67a73c5b310bd441fc4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOTM4OjE0N0VDMDo0MTdDRTA6NTZEMDQwOjZBNTI2MEUyIiwidmlzaXRvcl9pZCI6IjI5OTY2OTA3OTQwNzE2MTM2NjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9c51f5842948c98ecdfcef05019570b80eeb71c2db48dff0068487e197bb5fd7 |
| hovercard-subject-tag | issue:4526584606 |
| 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/matplotlib/matplotlib/31751/issue_layout |
| twitter:image | https://opengraph.githubassets.com/da4da70211b97581c8e71becf629bda2aaae1705685022594adc49ed6c2c7de1/matplotlib/matplotlib/issues/31751 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/da4da70211b97581c8e71becf629bda2aaae1705685022594adc49ed6c2c7de1/matplotlib/matplotlib/issues/31751 |
| og:image:alt | Bug summary I'm investigating #31106. At the time show(PyObject* self) is called, the window in question has a -retainCount of 600+. This is due to AppKit and other macOS frameworks calling [[theWi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | iccir |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| 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 | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width