[Image-SIG] memory leak error / PIL Image

nicholas Pye nick.pye at gmail.com
Thu Jan 1 22:12:28 CET 2009


I have a peice of code that repeatidly draws new images (draw_image)  
and then compares the images drawn against an origional image  

If I remove the PIL functions in these functions the rest of the code  
runs fine, and does not exhibit a memory leak, however when using PIL  
repeatidally in these functions I soon run out of memory. It's as if  
PIL is caching the images in memory or not cleaning up memory ... I've  
tried png, gif formats all eventually give a malloc of the period of  
the code run.


Python(2046) malloc: *** mmap(size=16777216) failed (error code=12)

def draw_image(popmember,path,img_tick,poly_vector_len):
     d = aggdraw.Draw(img)
     for strand in range(len(popmember)):
          vector = split_strand(popmember[strand],"vec",poly_vector_len)
          rgb = split_strand(popmember[strand],"rgb",poly_vector_len)
          alpha =  
          b = aggdraw.Brush(tuple(rgb),alpha[0])
     img.save(path + str(img_tick) + '.jpg','PNG')

def image_cost(path,image2,img_tick):
  h1 = Image.open(path+image2).histogram()
  h2 = Image.open(path+str(img_tick)+'.png').histogram()
  rms = math.sqrt(reduce(operator.add,map(lambda a,b: (a-b)**2, h1,  
  return rms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/image-sig/attachments/20090101/fd1b48f2/attachment-0001.htm>

More information about the Image-SIG mailing list