Skip to content

Memory leak in plt.close() when unshown figures in GUI backends are closed #20300

@P-Takenaka

Description

@P-Takenaka

Bug report

Bug summary

When creating multiple plots (e.g. in a loop), the allocated memory for the process increases in each iteration even though the figure is cleared each time.

Code for reproduction

import gc
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)
for i in range(5000):
    fig.clf()
    plt.cla()
    ax.plot([0,1,2,3,4,5], [0,1,2,3,4,5])
    plt.close('all')
    plt.close(fig)

    gc.collect()

Expected outcome

The allocated memory should not increase in each iteration.

Matplotlib version

  • Operating system: Arch Linux
  • Matplotlib version (import matplotlib; print(matplotlib.__version__)): 3.4.2
  • Matplotlib backend (print(matplotlib.get_backend())): TkAgg
  • Python version: 3.9.5
  • Jupyter version (if applicable):
  • Other libraries:

Matplotlib was installed via pip.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy