You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Perhaps also test the latest matplotlib. There were substantial changes to colorbar for 3.5. FWIW, I don;t know what make_axes is supposed to do in your code.
The culprit is parents = np.atleast_1d(parents).ravel(). If I get rid of this, no memory leak. However, this is needed, and I am not sure why it leaks.
Activity
vdrhtc commentedon Jan 2, 2022
Oh, also just found #22040, probably mine is a duplicate. The difference is that I do not yet know, how to workaround the problem in my example.
jklymak commentedon Jan 2, 2022
Perhaps also test the latest matplotlib. There were substantial changes to colorbar for 3.5. FWIW, I don;t know what make_axes is supposed to do in your code.
jklymak commentedon Jan 3, 2022
OK, I can confirm this when
make_axesis used. Whenmake_axes_gridspecis used, there is no memory leak.jklymak commentedon Jan 3, 2022
If I insert
... del ax del cax._colorbar_info del cax ...then the memory leak goes away.
This is defined in
make_axes:matplotlib/lib/matplotlib/colorbar.py
Lines 1463 to 1471 in 0c1aa86
and used by constrained_layout. I am not clear why adding a dictionary to an object would leave the dictionary orphaned when the parent is deleted?
vdrhtc commentedon Jan 3, 2022
Yes, I found that grid spec helps, too, thank you!
jklymak commentedon Jan 3, 2022
The culprit is
parents = np.atleast_1d(parents).ravel(). If I get rid of this, no memory leak. However, this is needed, and I am not sure why it leaks.vdrhtc commentedon Jan 3, 2022
@jklymak Thank you very much!