Title: Memory leaks on matplotlib 3.4.2 (and 3.4.0) · Issue #20490 · matplotlib/matplotlib · GitHub
Open Graph Title: Memory leaks on matplotlib 3.4.2 (and 3.4.0) · Issue #20490 · matplotlib/matplotlib
X Title: Memory leaks on matplotlib 3.4.2 (and 3.4.0) · Issue #20490 · matplotlib/matplotlib
Description: Bug report Bug summary Multiple different memory related errors when running as a part of script creating and saving lots of figures. Code for reproduction Sorry, could not create a minimal example that reproduces this. Just wanted to le...
Open Graph Description: Bug report Bug summary Multiple different memory related errors when running as a part of script creating and saving lots of figures. Code for reproduction Sorry, could not create a minimal example...
X Description: Bug report Bug summary Multiple different memory related errors when running as a part of script creating and saving lots of figures. Code for reproduction Sorry, could not create a minimal example...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/20490
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Memory leaks on matplotlib 3.4.2 (and 3.4.0)","articleBody":"\u003c!--To help us understand and resolve your issue, please fill out the form to the best of your ability.--\u003e\r\n\u003c!--You can feel free to delete the sections that do not apply.--\u003e\r\n\r\n### Bug report\r\n\r\n\r\n**Bug summary**\r\n\r\nMultiple different memory related errors when running as a part of script creating and saving lots of figures.\r\n\r\n\r\n**Code for reproduction**\r\n\r\nSorry, could not create a minimal example that reproduces this. Just wanted to leave a note. \r\n\r\n\r\n\r\n**Actual outcome**\r\n\r\nThere are multiple different errors that happen. Running the same script will produce different results randomly.\r\n\r\n\u003c!--The output produced by the above code, which may be a screenshot, console output, etc.--\u003e\r\n\r\n**Example 1**\r\nJust prints this. No Exceptions, nothing. Script stops running.\r\n```\r\nunable to alloc 4320000 bytes\r\n```\r\n\r\n**Example 2** \r\n\r\n```python\r\n File \"c:\\myapp\\calculations\\myscript.py\", line 422, in create_figure\r\n fig, ax = plt.subplots(nrows=1, figsize=(16, 9))\r\n File \"C:\\Python\\venvs\\adiapp\\lib\\site-packages\\matplotlib\\_api\\deprecation.py\", line 471, in wrapper\r\n return func(*args, **kwargs)\r\n File \"C:\\Python\\venvs\\adiapp\\lib\\site-packages\\matplotlib\\pyplot.py\", line 1439, in subplots\r\n fig = figure(**fig_kw)\r\n File \"C:\\Python\\venvs\\adiapp\\lib\\site-packages\\matplotlib\\pyplot.py\", line 797, in figure\r\n manager = new_figure_manager(\r\n File \"C:\\Python\\venvs\\adiapp\\lib\\site-packages\\matplotlib\\pyplot.py\", line 316, in new_figure_manager\r\n return _backend_mod.new_figure_manager(*args, **kwargs)\r\n File \"C:\\Python\\venvs\\adiapp\\lib\\site-packages\\matplotlib\\backend_bases.py\", line 3545, in new_figure_manager\r\n return cls.new_figure_manager_given_figure(num, fig)\r\n File \"C:\\Python\\venvs\\adiapp\\lib\\site-packages\\matplotlib\\backends\\_backend_tk.py\", line 899, in new_figure_manager_given_figure\r\n canvas = cls.FigureCanvas(figure, master=window)\r\n File \"C:\\Python\\venvs\\adiapp\\lib\\site-packages\\matplotlib\\_api\\deprecation.py\", line 431, in wrapper\r\n return func(*inner_args, **inner_kwargs)\r\n File \"C:\\Python\\venvs\\adiapp\\lib\\site-packages\\matplotlib\\backends\\_backend_tk.py\", line 174, in __init__\r\n self._tkphoto = tk.PhotoImage(\r\n File \"C:\\Python\\Python 3.8.6-32\\lib\\tkinter\\__init__.py\", line 4061, in __init__\r\n Image.__init__(self, 'photo', name, cnf, master, **kw)\r\n File \"C:\\Python\\Python 3.8.6-32\\lib\\tkinter\\__init__.py\", line 4006, in __init__\r\n self.tk.call(('image', 'create', imgtype, name,) + options)\r\n_tkinter.TclError: not enough free memory for image buffer\r\n```\r\n\r\n**Example 3**\r\n\r\n```python\r\n File \"c:\\myapp\\calculations\\myscript.py\", line 467, in create_some_figures\r\n plt.savefig(self.folder / \"myfig.png\")\r\n File \"C:\\Python\\venvs\\adiapp\\lib\\site-packages\\matplotlib\\pyplot.py\", line 966, in savefig\r\n res = fig.savefig(*args, **kwargs)\r\n File \"C:\\Python\\venvs\\adiapp\\lib\\site-packages\\matplotlib\\figure.py\", line 3005, in savefig\r\n self.canvas.print_figure(fname, **kwargs)\r\n File \"C:\\Python\\venvs\\adiapp\\lib\\site-packages\\matplotlib\\backend_bases.py\", line 2255, in print_figure\r\n result = print_method(\r\n File \"C:\\Python\\venvs\\adiapp\\lib\\site-packages\\matplotlib\\backend_bases.py\", line 1669, in wrapper\r\n return func(*args, **kwargs)\r\n File \"C:\\Python\\venvs\\adiapp\\lib\\site-packages\\matplotlib\\backends\\backend_agg.py\", line 508, in print_png\r\n FigureCanvasAgg.draw(self)\r\n File \"C:\\Python\\venvs\\adiapp\\lib\\site-packages\\matplotlib\\backends\\backend_agg.py\", line 401, in draw\r\n self.renderer = self.get_renderer(cleared=True)\r\n File \"C:\\Python\\venvs\\adiapp\\lib\\site-packages\\matplotlib\\backends\\backend_agg.py\", line 417, in get_renderer\r\n self.renderer = RendererAgg(w, h, self.figure.dpi)\r\n File \"C:\\Python\\venvs\\adiapp\\lib\\site-packages\\matplotlib\\backends\\backend_agg.py\", line 91, in __init__\r\n self._renderer = _RendererAgg(int(width), int(height), dpi)\r\nMemoryError: In RendererAgg: Out of memory\r\n```\r\n\r\n**Expected outcome**\r\n\r\n\u003c!--A description of the expected outcome from the code snippet--\u003e\r\n\u003c!--If this used to work in an earlier version of Matplotlib, please note the version it used to work on--\u003e\r\nNo errors. \r\n\r\n**Matplotlib version**\r\n\u003c!--Please specify your platform and versions of the relevant libraries you are using:--\u003e\r\n * Operating system: Windows 10\r\n * Matplotlib version (`import matplotlib; print(matplotlib.__version__)`): 3.4.2\r\n * Matplotlib backend (`print(matplotlib.get_backend())`): TkAgg \r\n * Python version: 32-bit 3.8.6 \r\n\r\n\r\n\u003c!--Please tell us how you installed matplotlib and python e.g., from source, pip, conda--\u003e\r\n\u003c!--If you installed from conda, please specify which channel you used if not the default--\u003e\r\n\r\n\r\n## Workaround\r\n\r\nAs a side note, tried on **version 3.3.4** and everything works. Does not work on 3.4.0. I'm calling \r\n\r\n```python\r\n plt.close(\"all\")\r\n plt.close()\r\n gc.collect()\r\n```\r\nafter every `plt.savefig()` just to be sure.\r\n","author":{"url":"https://github.com/fohrloop","@type":"Person","name":"fohrloop"},"datePublished":"2021-06-23T08:02:38.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/20490/matplotlib/issues/20490"}
| 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:97a42a6c-4480-4850-2ba6-ffae78929f53 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D68E:BFAF3:684118:8CECBF:6A51D3FF |
| html-safe-nonce | 59bce9e80207555591175587584474a17740e255aec8d8885f2a0ac2f52eb940 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENjhFOkJGQUYzOjY4NDExODo4Q0VDQkY6NkE1MUQzRkYiLCJ2aXNpdG9yX2lkIjoiNzA4ODY4Mzc1NTM0MzMwMzY3OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b997ff46fde542bcaf08437aa6542af9e77eb8c1388f2b731405d6d3efe7d0c0 |
| hovercard-subject-tag | issue:927973587 |
| 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/20490/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3594e4844d5f212b45a4b402faca858c7f9448ce6fb3f001fedce1e33e4ee223/matplotlib/matplotlib/issues/20490 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3594e4844d5f212b45a4b402faca858c7f9448ce6fb3f001fedce1e33e4ee223/matplotlib/matplotlib/issues/20490 |
| og:image:alt | Bug report Bug summary Multiple different memory related errors when running as a part of script creating and saving lots of figures. Code for reproduction Sorry, could not create a minimal example... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | fohrloop |
| 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