runtime error; producing multiple images

Hi folks,

I have a question I couldn't solve so far. I'm trying to generate say 500 images
(png) without displaying them using imshow. I wrote a simple test function
(see below) which I call from a loop in which I create the data for the image in
a sequence. I systematically bump into a runtime error after saving about 188
files. After reading the (excellent) tutorial from Perry Greenfield and
Robert Jedrzejewski on interactive data analysis, I understand the need to clean
up by freeing memory but I must be missing something else.



def generateImshow(yarray,
                   initimagesize = 10):
    '''Use this function to generate matplotlib images without displaying

    #reshape according to scan
    yarray = na.reshape(yarray,(yscansize,-1))

    #build image via matplotlib
    ximagesize = xscansize*xscanstep
    yimagesize = yscansize*yscanstep
    xyimageratio = float(ximagesize)/yimagesize
    print xyimageratio
    if xyimageratio > 1: ximagesize,yimagesize =
    else: ximagesize,yimagesize = initimagesize*xyimageratio,initimagesize

    fig1 = pylab.figure(figsize=(ximagesize,yimagesize),dpi=100)
    im1 = pylab.imshow(yarray,
                 #interpolation='nearest', #i.e. pixel
                 interpolation='bicubic', #i.e. smooth
       , #not correct

    #save figure
    #outputfilename = filename[:-4]+'.png'
    del im1