Bug report
Bug summary
Hi,
I believe I have found a memory issue when plotting multiple figures with the macOS backend.
Here is a minimal working example:
import sys
import matplotlib.pyplot as plt
import numpy as np
import matplotlib
#matplotlib.use('agg')
data = np.random.rand(60, 60)
def plot_expr(plot_name):
plt.figure(figsize=(9, 8))
for i in range(60):
plt.plot(data[i, :])
plt.savefig(plot_name)
plt.close('all')
if __name__ == "__main__":
print(f'python: {sys.version}')
print(f'matplotlib: {matplotlib.__version__}')
print(f'backend: {matplotlib.get_backend()}')
for i in range(50):
print(f'{i}...')
plot_expr(f'leak_{i}')
When running the code with memory-profiler, I obtain something like:

Even though I am explicitly calling the plt.close() function.
When using the 'agg' backend instead of the 'MacOSX' backend by uncommenting line 6, I get:

Which I would expect to be the normal behavior.
As I have been unable to reproduce this on Linux, I assume that the issue is with the macOS backend.
Matplotlib version
- Operating system:
macOS 11.2.1
- Matplotlib version
3.3.4
- Matplotlib backend
MacOSX
- Python version:
3.7.9
I installed Python via venv and matplotlib via pip.
Cheers,
Théotime
Bug report
Bug summary
Hi,
I believe I have found a memory issue when plotting multiple figures with the macOS backend.
Here is a minimal working example:
When running the code with

memory-profiler, I obtain something like:Even though I am explicitly calling the
plt.close()function.When using the

'agg'backend instead of the'MacOSX'backend by uncommenting line 6, I get:Which I would expect to be the normal behavior.
As I have been unable to reproduce this on Linux, I assume that the issue is with the macOS backend.
Matplotlib version
macOS 11.2.13.3.4MacOSX3.7.9I installed Python via
venvand matplotlib viapip.Cheers,
Théotime