On Thu, Jan 13, 2011 at 7:54 AM, CASOLI Jules <jules.casoli@cea.fr> wrote:
Hello to all,

This is yet another question about matplotlib not freeing memory, when closing a figure (using close()).
Here is what I'm doing (tried with several backends, on MacOSX and Linux, with similar results):
import matplotlib as mpl
from matplotlib import pylot as plt
import numpy as np

a = np.arange(1000000)
# -> output: 54256
# -> output: 139968
# -> output: 138748

Shouldn't plt.close() close the figure _and_ free the memory used by it?
What am I doing wrong ?
I tried several other ways to free the memory, such as f = figure(); ... ; del f, without luck.

Any help appreciated !

P.S. : side question : how come the call to plot take so much memory (90MB for a 8MB array ?). I have read somewhere that each point is coded on three RGB floats, but it only means an approx. 12MB plot... (plus small overhead)



Which version of Matplotlib are you using and which backend?  On my Linux install of matplotlib (development branch) using GTKAgg, the memory usage does get high during the call to show(), but returns to (near) normal amounts after I close.  An interesting observation is that if the interactive mode is off, the memory usage returns back to just a few kilobytes above where it was before, but if interactive mode was turned on, the memory usage returned to being a few hundred kilobytes above where it started.

Ben Root

P.S. - As a side note, estimating the memory size of these plots from the given data isn't as straight-forward as multiplying by three (actually, it would be four because of the transparency value in addition to rgb).  There are many other parts of the graph that needs to be represented (all having rgba values) but there are also a lot of simplifications that are done to reduce the amount of memory needed to represent these objects.