imshow memory leak in pylab mode?

Dear all,

I'm not sure if this is by design or a problem:

In a pylab session, if I repeatedly call imshow with the same image,
memory increases each time.
This does not happen if i go the 'Artists' way (fig = .., ax =
fig.add---, im = ax.imshow)
Is there a way to avoid memory consumption like this in the pylab style?
Even a clf() does not release the memory.
My config is the latest Enthought distribution in 32-bit mode for MacOS.

Can you post a complete free-standing script that we can run which
exposes the problem? Also please report your version numbers -- we
could look them up from enthought perhaps but you can help us :slight_smile:

Of course, sorry.
But because I don't know how to read out Python's memory consumption from within python, these lines should be run successively in Ipython, so that one can see, how the 'Real Mem' system indicator grows each time.

l = [28.1]
arr = ones((1500,1500,3))
l.append(79.7)
imshow(arr)
l.append(172.0)
imshow(arr)
l.append(249.0))
l.append(249.0)
imshow(arr)
l.append(326.3))
l.append(326.3)
imshow(arr)
l.append(404.4)
imshow(arr)
l.append(482.4)

This was run in an ipython session started with the -pylab flag.
The numbers in the l array are the MBs I read of Mac's Activity Monitor for the Python task.
Here is the resulting plot:
http://dl.dropbox.com/u/139035/mem_growth.png

Here's my system info:

Darwin paradigm.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386

In [25]: print matplotlib.__version__
-------> print(matplotlib.__version__)
0.99.3

Enthought Python Distribution -- http://code.enthought.com

Python 2.6.5 |EPD 6.2-2 (32-bit)| (r265:79063, May 28 2010, 15:13:03)

my matplotlibrc (some adaptations):
http://dl.dropbox.com/u/139035/matplotlibrc

Hope this is all you need?

BR,
Michael

···

On 2010-07-12 23:17:19 +0200, John Hunter said:

On Mon, Jul 12, 2010 at 4:06 PM, K.-Michael Aye > <kmichael.aye@...287...> wrote:

http://matplotlib.sourceforge.net/faq/troubleshooting_faq.html#troubleshooting

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first

It's by design and is not a leak. matplotlib supports multiple images
on the same axes, and can composite multiple images that overlap the
same space using transparency, so each call to imshow is adding
additional data to the axes. You can inspect the ax.images list to
see the list of images is growing.

If you have an Image object and want to remove it from the Axes, call

  im.remove()

or you can manipulate the list of ax.images directly, eg

  del ax.images[0]

or if you have a single image and want to update the data in it, you can do

  im = ax.imshow(something)
  im.set_array(newdata)

to update the array in the existing image.

JDH

···

On Mon, Jul 12, 2010 at 5:06 PM, K.-Michael Aye <kmichael.aye@...287...> wrote:

On 2010-07-12 23:17:19 +0200, John Hunter said:

On Mon, Jul 12, 2010 at 4:06 PM, K.-Michael Aye >> <kmichael.aye@...287...> wrote:

Dear all,

I'm not sure if this is by design or a problem: