Title: [Bug]: FontProperties objects are not deleted when using fig.savefig · Issue #28827 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: FontProperties objects are not deleted when using fig.savefig · Issue #28827 · matplotlib/matplotlib
X Title: [Bug]: FontProperties objects are not deleted when using fig.savefig · Issue #28827 · matplotlib/matplotlib
Description: Bug summary When repeatedly making a plot and saving it with fig.savefig, the number of FontProperties objects keep increasing. This does not occur without the savefig. Code for reproduction import gc from collections import Counter from...
Open Graph Description: Bug summary When repeatedly making a plot and saving it with fig.savefig, the number of FontProperties objects keep increasing. This does not occur without the savefig. Code for reproduction import...
X Description: Bug summary When repeatedly making a plot and saving it with fig.savefig, the number of FontProperties objects keep increasing. This does not occur without the savefig. Code for reproduction import...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/28827
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: FontProperties objects are not deleted when using fig.savefig","articleBody":"### Bug summary\n\nWhen repeatedly making a plot and saving it with fig.savefig, the number of FontProperties objects keep increasing. This does not occur without the savefig.\n\n### Code for reproduction\n\n```Python\nimport gc\r\nfrom collections import Counter\r\nfrom pathlib import Path\r\n\r\nimport matplotlib.pyplot as plt\r\n\r\nfor i in range(20):\r\n fig, ax = plt.subplots()\r\n fig.savefig(Path(f\"~/test_{i}.png\").expanduser())\r\n plt.close(fig)\r\n\r\n gc.collect()\r\n object_counts = Counter(f\"{type(obj).__module__}.{type(obj).__name__}\" for obj in gc.get_objects())\r\n print(object_counts['matplotlib.font_manager.FontProperties'], end=\", \")\n```\n\n\n### Actual outcome\n\n`43, 50, 57, 64, 71, 78, 85, 92, 99, 106, 113, 120, 127, 134, 141, 148, 155, 162, 169, 176, `\n\n### Expected outcome\n\n`43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, `\n\n### Additional information\n\n\u003cdetails\u003e\u003csummary\u003ercParams: \u003c/summary\u003e\r\n`\r\nRcParams({'_internal.classic_mode': False,\r\n 'agg.path.chunksize': 0,\r\n 'animation.bitrate': -1,\r\n 'animation.codec': 'h264',\r\n 'animation.convert_args': ['-layers', 'OptimizePlus'],\r\n 'animation.convert_path': 'convert',\r\n 'animation.embed_limit': 20.0,\r\n 'animation.ffmpeg_args': [],\r\n 'animation.ffmpeg_path': 'ffmpeg',\r\n 'animation.frame_format': 'png',\r\n 'animation.html': 'none',\r\n 'animation.writer': 'ffmpeg',\r\n 'axes.autolimit_mode': 'data',\r\n 'axes.axisbelow': 'line',\r\n 'axes.edgecolor': 'black',\r\n 'axes.facecolor': 'white',\r\n 'axes.formatter.limits': [-5, 6],\r\n 'axes.formatter.min_exponent': 0,\r\n 'axes.formatter.offset_threshold': 4,\r\n 'axes.formatter.use_locale': False,\r\n 'axes.formatter.use_mathtext': False,\r\n 'axes.formatter.useoffset': True,\r\n 'axes.grid': False,\r\n 'axes.grid.axis': 'both',\r\n 'axes.grid.which': 'major',\r\n 'axes.labelcolor': 'black',\r\n 'axes.labelpad': 4.0,\r\n 'axes.labelsize': 'medium',\r\n 'axes.labelweight': 'normal',\r\n 'axes.linewidth': 0.8,\r\n 'axes.prop_cycle': cycler('color', ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf']),\r\n 'axes.spines.bottom': True,\r\n 'axes.spines.left': True,\r\n 'axes.spines.right': True,\r\n 'axes.spines.top': True,\r\n 'axes.titlecolor': 'auto',\r\n 'axes.titlelocation': 'center',\r\n 'axes.titlepad': 6.0,\r\n 'axes.titlesize': 'large',\r\n 'axes.titleweight': 'normal',\r\n 'axes.titley': None,\r\n 'axes.unicode_minus': True,\r\n 'axes.xmargin': 0.05,\r\n 'axes.ymargin': 0.05,\r\n 'axes.zmargin': 0.05,\r\n 'axes3d.grid': True,\r\n 'axes3d.xaxis.panecolor': (0.95, 0.95, 0.95, 0.5),\r\n 'axes3d.yaxis.panecolor': (0.9, 0.9, 0.9, 0.5),\r\n 'axes3d.zaxis.panecolor': (0.925, 0.925, 0.925, 0.5),\r\n 'backend': 'Qt5Agg',\r\n 'backend_fallback': True,\r\n 'boxplot.bootstrap': None,\r\n 'boxplot.boxprops.color': 'black',\r\n 'boxplot.boxprops.linestyle': '-',\r\n 'boxplot.boxprops.linewidth': 1.0,\r\n 'boxplot.capprops.color': 'black',\r\n 'boxplot.capprops.linestyle': '-',\r\n 'boxplot.capprops.linewidth': 1.0,\r\n 'boxplot.flierprops.color': 'black',\r\n 'boxplot.flierprops.linestyle': 'none',\r\n 'boxplot.flierprops.linewidth': 1.0,\r\n 'boxplot.flierprops.marker': 'o',\r\n 'boxplot.flierprops.markeredgecolor': 'black',\r\n 'boxplot.flierprops.markeredgewidth': 1.0,\r\n 'boxplot.flierprops.markerfacecolor': 'none',\r\n 'boxplot.flierprops.markersize': 6.0,\r\n 'boxplot.meanline': False,\r\n 'boxplot.meanprops.color': 'C2',\r\n 'boxplot.meanprops.linestyle': '--',\r\n 'boxplot.meanprops.linewidth': 1.0,\r\n 'boxplot.meanprops.marker': '^',\r\n 'boxplot.meanprops.markeredgecolor': 'C2',\r\n 'boxplot.meanprops.markerfacecolor': 'C2',\r\n 'boxplot.meanprops.markersize': 6.0,\r\n 'boxplot.medianprops.color': 'C1',\r\n 'boxplot.medianprops.linestyle': '-',\r\n 'boxplot.medianprops.linewidth': 1.0,\r\n 'boxplot.notch': False,\r\n 'boxplot.patchartist': False,\r\n 'boxplot.showbox': True,\r\n 'boxplot.showcaps': True,\r\n 'boxplot.showfliers': True,\r\n 'boxplot.showmeans': False,\r\n 'boxplot.vertical': True,\r\n 'boxplot.whiskerprops.color': 'black',\r\n 'boxplot.whiskerprops.linestyle': '-',\r\n 'boxplot.whiskerprops.linewidth': 1.0,\r\n 'boxplot.whiskers': 1.5,\r\n 'contour.algorithm': 'mpl2014',\r\n 'contour.corner_mask': True,\r\n 'contour.linewidth': None,\r\n 'contour.negative_linestyle': 'dashed',\r\n 'date.autoformatter.day': '%Y-%m-%d',\r\n 'date.autoformatter.hour': '%m-%d %H',\r\n 'date.autoformatter.microsecond': '%M:%S.%f',\r\n 'date.autoformatter.minute': '%d %H:%M',\r\n 'date.autoformatter.month': '%Y-%m',\r\n 'date.autoformatter.second': '%H:%M:%S',\r\n 'date.autoformatter.year': '%Y',\r\n 'date.converter': 'auto',\r\n 'date.epoch': '1970-01-01T00:00:00',\r\n 'date.interval_multiples': True,\r\n 'docstring.hardcopy': False,\r\n 'errorbar.capsize': 0.0,\r\n 'figure.autolayout': False,\r\n 'figure.constrained_layout.h_pad': 0.04167,\r\n 'figure.constrained_layout.hspace': 0.02,\r\n 'figure.constrained_layout.use': False,\r\n 'figure.constrained_layout.w_pad': 0.04167,\r\n 'figure.constrained_layout.wspace': 0.02,\r\n 'figure.dpi': 100.0,\r\n 'figure.edgecolor': 'white',\r\n 'figure.facecolor': 'white',\r\n 'figure.figsize': [6.4, 4.8],\r\n 'figure.frameon': True,\r\n 'figure.hooks': [],\r\n 'figure.labelsize': 'large',\r\n 'figure.labelweight': 'normal',\r\n 'figure.max_open_warning': 20,\r\n 'figure.raise_window': True,\r\n 'figure.subplot.bottom': 0.11,\r\n 'figure.subplot.hspace': 0.2,\r\n 'figure.subplot.left': 0.125,\r\n 'figure.subplot.right': 0.9,\r\n 'figure.subplot.top': 0.88,\r\n 'figure.subplot.wspace': 0.2,\r\n 'figure.titlesize': 'large',\r\n 'figure.titleweight': 'normal',\r\n 'font.cursive': ['Apple Chancery',\r\n 'Textile',\r\n 'Zapf Chancery',\r\n 'Sand',\r\n 'Script MT',\r\n 'Felipa',\r\n 'Comic Neue',\r\n 'Comic Sans MS',\r\n 'cursive'],\r\n 'font.family': ['sans-serif'],\r\n 'font.fantasy': ['Chicago',\r\n 'Charcoal',\r\n 'Impact',\r\n 'Western',\r\n 'xkcd script',\r\n 'fantasy'],\r\n 'font.monospace': ['DejaVu Sans Mono',\r\n 'Bitstream Vera Sans Mono',\r\n 'Computer Modern Typewriter',\r\n 'Andale Mono',\r\n 'Nimbus Mono L',\r\n 'Courier New',\r\n 'Courier',\r\n 'Fixed',\r\n 'Terminal',\r\n 'monospace'],\r\n 'font.sans-serif': ['DejaVu Sans',\r\n 'Bitstream Vera Sans',\r\n 'Computer Modern Sans Serif',\r\n 'Lucida Grande',\r\n 'Verdana',\r\n 'Geneva',\r\n 'Lucid',\r\n 'Arial',\r\n 'Helvetica',\r\n 'Avant Garde',\r\n 'sans-serif'],\r\n 'font.serif': ['DejaVu Serif',\r\n 'Bitstream Vera Serif',\r\n 'Computer Modern Roman',\r\n 'New Century Schoolbook',\r\n 'Century Schoolbook L',\r\n 'Utopia',\r\n 'ITC Bookman',\r\n 'Bookman',\r\n 'Nimbus Roman No9 L',\r\n 'Times New Roman',\r\n 'Times',\r\n 'Palatino',\r\n 'Charter',\r\n 'serif'],\r\n 'font.size': 10.0,\r\n 'font.stretch': 'normal',\r\n 'font.style': 'normal',\r\n 'font.variant': 'normal',\r\n 'font.weight': 'normal',\r\n 'grid.alpha': 1.0,\r\n 'grid.color': '#b0b0b0',\r\n 'grid.linestyle': '-',\r\n 'grid.linewidth': 0.8,\r\n 'hatch.color': 'black',\r\n 'hatch.linewidth': 1.0,\r\n 'hist.bins': 10,\r\n 'image.aspect': 'equal',\r\n 'image.cmap': 'viridis',\r\n 'image.composite_image': True,\r\n 'image.interpolation': 'antialiased',\r\n 'image.lut': 256,\r\n 'image.origin': 'upper',\r\n 'image.resample': True,\r\n 'interactive': True,\r\n 'keymap.back': ['left', 'c', 'backspace', 'MouseButton.BACK'],\r\n 'keymap.copy': ['ctrl+c', 'cmd+c'],\r\n 'keymap.forward': ['right', 'v', 'MouseButton.FORWARD'],\r\n 'keymap.fullscreen': ['f', 'ctrl+f'],\r\n 'keymap.grid': ['g'],\r\n 'keymap.grid_minor': ['G'],\r\n 'keymap.help': ['f1'],\r\n 'keymap.home': ['h', 'r', 'home'],\r\n 'keymap.pan': ['p'],\r\n 'keymap.quit': ['ctrl+w', 'cmd+w', 'q'],\r\n 'keymap.quit_all': [],\r\n 'keymap.save': ['s', 'ctrl+s'],\r\n 'keymap.xscale': ['k', 'L'],\r\n 'keymap.yscale': ['l'],\r\n 'keymap.zoom': ['o'],\r\n 'legend.borderaxespad': 0.5,\r\n 'legend.borderpad': 0.4,\r\n 'legend.columnspacing': 2.0,\r\n 'legend.edgecolor': '0.8',\r\n 'legend.facecolor': 'inherit',\r\n 'legend.fancybox': True,\r\n 'legend.fontsize': 'medium',\r\n 'legend.framealpha': 0.8,\r\n 'legend.frameon': True,\r\n 'legend.handleheight': 0.7,\r\n 'legend.handlelength': 2.0,\r\n 'legend.handletextpad': 0.8,\r\n 'legend.labelcolor': 'None',\r\n 'legend.labelspacing': 0.5,\r\n 'legend.loc': 'best',\r\n 'legend.markerscale': 1.0,\r\n 'legend.numpoints': 1,\r\n 'legend.scatterpoints': 1,\r\n 'legend.shadow': False,\r\n 'legend.title_fontsize': None,\r\n 'lines.antialiased': True,\r\n 'lines.color': 'C0',\r\n 'lines.dash_capstyle': \u003cCapStyle.butt: 'butt'\u003e,\r\n 'lines.dash_joinstyle': \u003cJoinStyle.round: 'round'\u003e,\r\n 'lines.dashdot_pattern': [6.4, 1.6, 1.0, 1.6],\r\n 'lines.dashed_pattern': [3.7, 1.6],\r\n 'lines.dotted_pattern': [1.0, 1.65],\r\n 'lines.linestyle': '-',\r\n 'lines.linewidth': 1.5,\r\n 'lines.marker': 'None',\r\n 'lines.markeredgecolor': 'auto',\r\n 'lines.markeredgewidth': 1.0,\r\n 'lines.markerfacecolor': 'auto',\r\n 'lines.markersize': 6.0,\r\n 'lines.scale_dashes': True,\r\n 'lines.solid_capstyle': \u003cCapStyle.projecting: 'projecting'\u003e,\r\n 'lines.solid_joinstyle': \u003cJoinStyle.round: 'round'\u003e,\r\n 'macosx.window_mode': 'system',\r\n 'markers.fillstyle': 'full',\r\n 'mathtext.bf': 'sans:bold',\r\n 'mathtext.bfit': 'sans:italic:bold',\r\n 'mathtext.cal': 'cursive',\r\n 'mathtext.default': 'it',\r\n 'mathtext.fallback': 'cm',\r\n 'mathtext.fontset': 'dejavusans',\r\n 'mathtext.it': 'sans:italic',\r\n 'mathtext.rm': 'sans',\r\n 'mathtext.sf': 'sans',\r\n 'mathtext.tt': 'monospace',\r\n 'patch.antialiased': True,\r\n 'patch.edgecolor': 'black',\r\n 'patch.facecolor': 'C0',\r\n 'patch.force_edgecolor': False,\r\n 'patch.linewidth': 1.0,\r\n 'path.effects': [],\r\n 'path.simplify': True,\r\n 'path.simplify_threshold': 0.111111111111,\r\n 'path.sketch': None,\r\n 'path.snap': True,\r\n 'pcolor.shading': 'auto',\r\n 'pcolormesh.snap': True,\r\n 'pdf.compression': 6,\r\n 'pdf.fonttype': 3,\r\n 'pdf.inheritcolor': False,\r\n 'pdf.use14corefonts': False,\r\n 'pgf.preamble': '',\r\n 'pgf.rcfonts': True,\r\n 'pgf.texsystem': 'xelatex',\r\n 'polaraxes.grid': True,\r\n 'ps.distiller.res': 6000,\r\n 'ps.fonttype': 3,\r\n 'ps.papersize': 'letter',\r\n 'ps.useafm': False,\r\n 'ps.usedistiller': None,\r\n 'savefig.bbox': None,\r\n 'savefig.directory': '~',\r\n 'savefig.dpi': 'figure',\r\n 'savefig.edgecolor': 'auto',\r\n 'savefig.facecolor': 'auto',\r\n 'savefig.format': 'png',\r\n 'savefig.orientation': 'portrait',\r\n 'savefig.pad_inches': 0.1,\r\n 'savefig.transparent': False,\r\n 'scatter.edgecolors': 'face',\r\n 'scatter.marker': 'o',\r\n 'svg.fonttype': 'path',\r\n 'svg.hashsalt': None,\r\n 'svg.image_inline': True,\r\n 'text.antialiased': True,\r\n 'text.color': 'black',\r\n 'text.hinting': 'force_autohint',\r\n 'text.hinting_factor': 8,\r\n 'text.kerning_factor': 0,\r\n 'text.latex.preamble': '',\r\n 'text.parse_math': True,\r\n 'text.usetex': False,\r\n 'timezone': 'UTC',\r\n 'tk.window_focus': False,\r\n 'toolbar': 'toolbar2',\r\n 'webagg.address': '127.0.0.1',\r\n 'webagg.open_in_browser': True,\r\n 'webagg.port': 8988,\r\n 'webagg.port_retries': 50,\r\n 'xaxis.labellocation': 'center',\r\n 'xtick.alignment': 'center',\r\n 'xtick.bottom': True,\r\n 'xtick.color': 'black',\r\n 'xtick.direction': 'out',\r\n 'xtick.labelbottom': True,\r\n 'xtick.labelcolor': 'inherit',\r\n 'xtick.labelsize': 'medium',\r\n 'xtick.labeltop': False,\r\n 'xtick.major.bottom': True,\r\n 'xtick.major.pad': 3.5,\r\n 'xtick.major.size': 3.5,\r\n 'xtick.major.top': True,\r\n 'xtick.major.width': 0.8,\r\n 'xtick.minor.bottom': True,\r\n 'xtick.minor.ndivs': 'auto',\r\n 'xtick.minor.pad': 3.4,\r\n 'xtick.minor.size': 2.0,\r\n 'xtick.minor.top': True,\r\n 'xtick.minor.visible': False,\r\n 'xtick.minor.width': 0.6,\r\n 'xtick.top': False,\r\n 'yaxis.labellocation': 'center',\r\n 'ytick.alignment': 'center_baseline',\r\n 'ytick.color': 'black',\r\n 'ytick.direction': 'out',\r\n 'ytick.labelcolor': 'inherit',\r\n 'ytick.labelleft': True,\r\n 'ytick.labelright': False,\r\n 'ytick.labelsize': 'medium',\r\n 'ytick.left': True,\r\n 'ytick.major.left': True,\r\n 'ytick.major.pad': 3.5,\r\n 'ytick.major.right': True,\r\n 'ytick.major.size': 3.5,\r\n 'ytick.major.width': 0.8,\r\n 'ytick.minor.left': True,\r\n 'ytick.minor.ndivs': 'auto',\r\n 'ytick.minor.pad': 3.4,\r\n 'ytick.minor.right': True,\r\n 'ytick.minor.size': 2.0,\r\n 'ytick.minor.visible': False,\r\n 'ytick.minor.width': 0.6,\r\n 'ytick.right': False})\r\n`\r\n\u003c/details\u003e\r\n\r\nThis happens with both the \"Qt5Agg\" and \"Agg\" backends.\n\n### Operating system\n\nWindows\n\n### Matplotlib Version\n\n3.8.4\n\n### Matplotlib Backend\n\nQt5Agg\n\n### Python version\n\n3.10.11\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\npip","author":{"url":"https://github.com/haroldmeerwaldt","@type":"Person","name":"haroldmeerwaldt"},"datePublished":"2024-09-16T12:01:52.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/28827/matplotlib/issues/28827"}
| 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:42fbc4e2-b036-bc07-adf6-fba711bcb60a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C004:26F033:7B1492:A7BC63:6A525B39 |
| html-safe-nonce | 0e1bd594f0c4dc0c6d0db330255a91b239ae9c715a4c468551e34c4a27f7d46c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMDA0OjI2RjAzMzo3QjE0OTI6QTdCQzYzOjZBNTI1QjM5IiwidmlzaXRvcl9pZCI6IjY1Mzg5MjY3MjE2ODQ2MjYyMzMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c109498ddcd3104103bf0c3cf37e755c9cf63d72b95b1b99c523b735671a222d |
| hovercard-subject-tag | issue:2528268858 |
| 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/28827/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0b6cc54f272f7f168d2fbb90a7b30498fa9a3b49df16aae11b6f5590e792be8b/matplotlib/matplotlib/issues/28827 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0b6cc54f272f7f168d2fbb90a7b30498fa9a3b49df16aae11b6f5590e792be8b/matplotlib/matplotlib/issues/28827 |
| og:image:alt | Bug summary When repeatedly making a plot and saving it with fig.savefig, the number of FontProperties objects keep increasing. This does not occur without the savefig. Code for reproduction import... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | haroldmeerwaldt |
| 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