Memory trouble with imshow

Dear all,

I ran into a memory problem when trying to draw a few hundred png files using one imshow per file. The problem can be boiled down to the attached code which eats my memory very quickly until Python bombs out. I tried to "del" objects after their use, looked for garbage and read the user manual, but no luck. Did I do anything wrong or is this a memory leak?

Cheers,
Leif

# discovered odd behaviour in relation to the imshow function
# memory usage will go up quickly until the runtime breaks
# watch it with the task manager

# lxo, 19.02.2008
# running matplotlib-0.91.2.win32-py2.5.exe with wxPython 2.8.4.0 on Python 2.5.1

from pylab import *
import gc
for i in range (1000):
   A=rand(1024,1024)
   im = imshow(A)
   #del A #doesn't help
   #del im #doesn't help
   #print gc.garbage # no garbage

This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

matplotlib overplots by default -- try setting

  hold(False)

before your loop, and call gc.collect() occassionally

eg

  if (i%100)==0: gc.collect()

JDH

···

On Feb 19, 2008 8:37 AM, Leif Oppermann <lxo@...1884...> wrote:

from pylab import *
import gc
for i in range (1000):
   A=rand(1024,1024)
   im = imshow(A)
   #del A #doesn't help
   #del im #doesn't help
   #print gc.garbage # no garbage