On 02/02/2011 08:38 PM, Robert Abiad wrote:

[...]
I'll put it in as an enhancement, but I'm still unsure if there is a bug in
there as well.  Is there something I should be doing to clear memory after the
first figure is closed other than close()?  I don't understand why memory usage
grows each time I replot, but I'm pretty sure it isn't desireable behavior.  As
I mentioned, this effect is worse with plot.

So is this a bug or improper usage?

I'm not quite sure, but I don't think there is a specifically matplotlib memory leak bug at work here. Are you using ipython, and if so, have you turned off the caching? In its default mode, ipython keeps lots of references, thereby keeping memory in use. Also, memory management and reporting can be a bit tricky and misleading.

Nevertheless, the attached script may be illustrating the problem. Try running it from the command line as-is (maybe shorten the loop--it doesn't take 100 iterations to show the pattern) and then commenting out the line as indicated in the comment. It seems that if anything is done that adds ever so slightly to memory use while the figure is displayed, then when the figure is closed, its memory is not reused. I'm puzzled.

Eric


As for how to implement a fix for memory usage, I'll let you folks figure that
out.  But it seems that if I want a grayscale image, I could reduce memory usage
by 4 if matplotlib could turn rgba into intensity.

-robert
import time
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.cbook import report_memory

plt.ion()

stuff = []
for i in range(100):
    z = np.random.rand(2000, 2000)
    plt.imshow(z)
    plt.draw()
    time.sleep(0.5)
    plt.close('all')
    # Comment the following line, and the memory use is stable.
    stuff.append(z[0])
    print report_memory()


------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to