Title: Possible memory leak in pybind11 migration · Issue #28866 · matplotlib/matplotlib · GitHub
Open Graph Title: Possible memory leak in pybind11 migration · Issue #28866 · matplotlib/matplotlib
X Title: Possible memory leak in pybind11 migration · Issue #28866 · matplotlib/matplotlib
Description: Hi @QuLogic, I think I might have found an issue with this commit. I'm not sure if this is the right forum (or if I should create an issue?). I suspect this commit is causing a memory usage growth, even after running the garbage collecto...
Open Graph Description: Hi @QuLogic, I think I might have found an issue with this commit. I'm not sure if this is the right forum (or if I should create an issue?). I suspect this commit is causing a memory usage growth,...
X Description: Hi @QuLogic, I think I might have found an issue with this commit. I'm not sure if this is the right forum (or if I should create an issue?). I suspect this commit is causing a memory usage gro...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/28866
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Possible memory leak in pybind11 migration","articleBody":"\u003e Hi @QuLogic, I think I might have found an issue with this commit. I'm not sure if this is the right forum (or if I should create an issue?). I suspect this commit is causing a memory usage growth, even after running the garbage collector. I've only tested it on Windows 10 with python3.11. Can you reproduce this behavior? Details below.\r\u003e \n\u003e \r\u003e \n\u003e **memory_usage_test.py**\r\u003e \n\u003e ```python\r\u003e \n\u003e import gc\r\u003e \n\u003e from matplotlib.figure import Figure\r\u003e \n\u003e from numpy.random import rand\r\u003e \n\u003e import psutil\r\u003e \n\u003e \r\u003e \n\u003e def plot(num_points):\r\u003e \n\u003e fig = Figure()\r\u003e \n\u003e ax = fig.add_subplot()\r\u003e \n\u003e ax.plot(rand(num_points))\r\u003e \n\u003e fig.clear()\r\u003e \n\u003e \r\u003e \n\u003e def delta_mb_after_plot_and_gc(num_points):\r\u003e \n\u003e proc = psutil.Process()\r\u003e \n\u003e before_mb = proc.memory_info().rss / 1e6\r\u003e \n\u003e plot(num_points)\r\u003e \n\u003e gc.collect()\r\u003e \n\u003e after_mb = proc.memory_info().rss / 1e6\r\u003e \n\u003e delta_mb = after_mb - before_mb\r\u003e \n\u003e print(f\"plotting {num_points} points leaks {delta_mb:.3f} MB\")\r\u003e \n\u003e \r\u003e \n\u003e def main():\r\u003e \n\u003e gc.disable()\r\u003e \n\u003e delta_mb_after_plot_and_gc(100_000)\r\u003e \n\u003e delta_mb_after_plot_and_gc(1_000_000)\r\u003e \n\u003e delta_mb_after_plot_and_gc(10_000_000)\r\u003e \n\u003e \r\u003e \n\u003e if __name__ == \"__main__\":\r\u003e \n\u003e main()\r\u003e \n\u003e ```\r\u003e \n\u003e \r\u003e \n\u003e Running it against this commit and the previous commit (I found this commit via git bisect)\r\u003e \n\u003e ```\r\u003e \n\u003e (mpl_venv) PS C:\\Users\\justi\\projects\\matplotlib_ref_cycle\\matplotlib\u003e git checkout 597554db667344c4c4ad026ec1c6dd5f4c688d8f\r\u003e \n\u003e HEAD is now at 597554db66 Add a pybind11 type caster for GCAgg and its requirements\r\u003e \n\u003e \r\u003e \n\u003e (mpl_venv) PS C:\\Users\\justi\\projects\\matplotlib_ref_cycle\\matplotlib\u003e python ..\\memory_usage_test.py\r\u003e \n\u003e plotting 100000 points leaks 1.978 MB\r\u003e \n\u003e plotting 1000000 points leaks 16.077 MB\r\u003e \n\u003e plotting 10000000 points leaks 159.719 MB\r\u003e \n\u003e \r\u003e \n\u003e (mpl_venv) PS C:\\Users\\justi\\projects\\matplotlib_ref_cycle\\matplotlib\u003e python ..\\memory_usage_test.py\r\u003e \n\u003e plotting 100000 points leaks 1.970 MB\r\u003e \n\u003e plotting 1000000 points leaks 16.081 MB\r\u003e \n\u003e plotting 10000000 points leaks 159.625 MB\r\u003e \n\u003e \r\u003e \n\u003e (mpl_venv) PS C:\\Users\\justi\\projects\\matplotlib_ref_cycle\\matplotlib\u003e git checkout a47e26bd8583f0fcacc1dd83c3f2ac39b1f7a091\r\u003e \n\u003e Previous HEAD position was 597554db66 Add a pybind11 type caster for GCAgg and its requirements\r\u003e \n\u003e HEAD is now at a47e26bd85 Add a pybind11 type caster for agg::rgba\r\u003e \n\u003e \r\u003e \n\u003e (mpl_venv) PS C:\\Users\\justi\\projects\\matplotlib_ref_cycle\\matplotlib\u003e python ..\\memory_usage_test.py\r\u003e \n\u003e plotting 100000 points leaks 0.303 MB\r\u003e \n\u003e plotting 1000000 points leaks 0.041 MB\r\u003e \n\u003e plotting 10000000 points leaks -0.279 MB\r\u003e \n\u003e \r\u003e \n\u003e (mpl_venv) PS C:\\Users\\justi\\projects\\matplotlib_ref_cycle\\matplotlib\u003e python ..\\memory_usage_test.py\r\u003e \n\u003e plotting 100000 points leaks 0.197 MB\r\u003e \n\u003e plotting 1000000 points leaks 0.041 MB\r\u003e \n\u003e plotting 10000000 points leaks -0.311 MB\r\u003e \n\u003e ```\r\u003e \n\u003e \r\u003e \n\u003e Environment Details\r\u003e \n\u003e ```\r\u003e \n\u003e (mpl_venv) PS C:\\Users\\justi\\projects\\matplotlib_ref_cycle\\matplotlib\u003e python --version\r\u003e \n\u003e Python 3.11.9\r\u003e \n\u003e \r\u003e \n\u003e (mpl_venv) PS C:\\Users\\justi\\projects\\matplotlib_ref_cycle\\matplotlib\u003e [System.Environment]::OSVersion.Version\r\u003e \n\u003e Major Minor Build Revision\r\u003e \n\u003e ----- ----- ----- --------\r\u003e \n\u003e 10 0 19045 0\r\u003e \n\u003e \r\u003e \n\u003e (mpl_venv) PS C:\\Users\\justi\\projects\\matplotlib_ref_cycle\\matplotlib\u003e pip freeze | findstr matplotlib\r\u003e \n\u003e -e git+https://github.com/justinjhendrick/matplotlib.git@a47e26bd8583f0fcacc1dd83c3f2ac39b1f7a091#egg=matplotlib\r\u003e \n\u003e matplotlib-inline==0.1.7\r\u003e \n\u003e ``` \n\n _Originally posted by @justinjhendrick in [597554d](https://github.com/matplotlib/matplotlib/commit/597554db667344c4c4ad026ec1c6dd5f4c688d8f#commitcomment-147024800)_","author":{"url":"https://github.com/tacaswell","@type":"Person","name":"tacaswell"},"datePublished":"2024-09-23T09:31:58.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/28866/matplotlib/issues/28866"}
| 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:13f36cc5-6e76-25b2-ae1f-00717bf7a0da |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8A48:186324:3EED1:5150A:6A527E96 |
| html-safe-nonce | b0dfeec33153ea99abd92b0b829496068ccb6894d91ea7255eda564abcad1243 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QTQ4OjE4NjMyNDozRUVEMTo1MTUwQTo2QTUyN0U5NiIsInZpc2l0b3JfaWQiOiIxMjkxMjkwNTAwNjcwODQ4NjYyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 85b991cdc049850bd44780e647dc4daefd4875c3935a64c9a1ac7412fe5175cb |
| hovercard-subject-tag | issue:2542068884 |
| 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/28866/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1a2ca971aa9be5abcfa1dc64f0962ec1c1316d29327512b67bf0f1aaed6f53de/matplotlib/matplotlib/issues/28866 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1a2ca971aa9be5abcfa1dc64f0962ec1c1316d29327512b67bf0f1aaed6f53de/matplotlib/matplotlib/issues/28866 |
| og:image:alt | Hi @QuLogic, I think I might have found an issue with this commit. I'm not sure if this is the right forum (or if I should create an issue?). I suspect this commit is causing a memory usage growth,... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tacaswell |
| 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 | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width