[Image-SIG] malloc error
Fredrik Lundh
fredrik at pythonware.com
Mon Jan 5 17:41:24 CET 2009
What version of aggdraw are you using? The Draw(im) form is buggy in
some versions; it doesn't release the im object when the draw object
goes away. Here's a workaround (cut and pasted from an old message to
this list):
as a workaround, you can use the original constructor syntax instead,
together with fromstring/tostring:
d = Draw(im.mode, im.size)
d.fromstring(im.tostring())
# draw your stuff
im.fromstring(d.tostring())
</F>
2008/12/31 nicholas Pye <nick.pye at gmail.com>:
> Hello,
> I have a peice of code that repeatidly draws new images (draw_image) and
> then compares the images drawn against an origional image (image_cost).
> 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.
> error
> Python(2046) malloc: *** mmap(size=16777216) failed (error code=12)
>
> def draw_image(popmember,path,img_tick,poly_vector_len):
> img=Image.new('RGB',(300,300),(0,0,0))
> 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 = split_strand(popmember[strand],"alpha",poly_vector_len)
> b = aggdraw.Brush(tuple(rgb),alpha[0])
> d.polygon(vector,b)
> d.flush()
> 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,
> h2))/len(h1))
> return rms
> _______________________________________________
> Image-SIG maillist - Image-SIG at python.org
> http://mail.python.org/mailman/listinfo/image-sig
>
>
More information about the Image-SIG
mailing list