Skip to content

[Bug]: Memory leak with colorbar.make_axes #22085

Closed
@vdrhtc

Description

@vdrhtc

Bug summary

When using matplotlib.colorbar.make_axes function, plt.close() does not clear the new colorbar axes from memory. Tested for the Qt5 backend only. Maybe related to #22002, at least in the sense that I see no leak for Qt5 when no colorbar axes are added.

Code for reproduction

%pylab qt5
from matplotlib import colorbar
import psutil
import gc

p = psutil.Process()
for i in range(5):
    fig, ax = plt.subplots(1,1)
    ax.imshow(random.normal(size=(100,100)))
    cax = colorbar.make_axes(ax)
    plt.savefig("test.png")
    plt.pause(0.1)
    plt.close(fig)
    del fig
    del ax
    del cax
    gc.collect()
    print(p.memory_full_info().uss/1e6)

Actual outcome

250.744832
255.209472
259.514368
264.13056
268.099584

Expected outcome

Constant memory usage, as is when the line
cax = colorbar.make_axes(ax)
is commented out.

Additional information

No response

Operating system

Windows

Matplotlib Version

3.4.2

Matplotlib Backend

Qt5Agg (PyQt)

Python version

3.7.6

Jupyter version

No response

Installation

from source (.tar.gz)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions