You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it doesnt happen in py3.4 pillow <= 4.1.1
it does in >= 4.20
ImageFont.py leaks memory, it happens on default font, but even more on external loaded font with truetype
when running the script below on version 4.2.0+
mem usage keeps increasing every cycle for :
/usr/local/lib/python3.4/dist-packages/PIL/ImageFont.py:113
/usr/local/lib/python3.4/dist-packages/PIL/ImageFont.py:113: size=15.9 KiB (+15.9 KiB), count=709 (+708), average=23 B
/usr/local/lib/python3.4/dist-packages/PIL/ImageFont.py:113: size=17.2 KiB (+17.2 KiB), count=768 (+767), average=23 B
/usr/local/lib/python3.4/dist-packages/PIL/ImageFont.py:113: size=18.6 KiB (+18.6 KiB), count=827 (+826), average=23 B
fromPILimportImage, ImageFont, ImageDraw, ImageFontimporttracemalloctracemalloc.start()
count=0size=128, 128#font2 = ImageFont.truetype('/home/pi/run/fonts/04B_03__.TTF',8) ##use this with own font for more leakingtxt=Image.new('RGBA', size, (255,255,255,0))
d=ImageDraw.Draw(txt)
font2=ImageFont.load_default()
whileTrue :
d.text((0, 0), "blabla", font=font2, fill="white")
ifcount<=0:
snapshot1=tracemalloc.take_snapshot()
count+=1ifcount==60 :
snapshot2=tracemalloc.take_snapshot()
count=1top_stats=snapshot2.compare_to(snapshot1, 'lineno')
print("[ Top 10 differences ]")
forstatintop_stats[:10]:
print(stat)
I've got it leaking in Py3.5, in 4.1.0 and 4.2.1, though the location in 4.1.0 seems off. Similar leak sizes, but not the same. OTOH, I'm not on ARM, so that's not unexpected.
PyUnicode_AsLatin1String returns a new reference, which is then used by PyBytes_AsString to give us a char* pointer. But it's never freed, it's just dropped. It can't be freed here, because it needs to live as long as the text pointer is alive.
This code is likely the root of #2620 as well, as it's common to both code paths and it's the only place latin1 is mentioned.
Activity
wiredfool commentedon Jul 17, 2017
Do you have raqm support in 4.2.0?
This shouldn't affect the default font, but it may point to something.
gompa commentedon Jul 17, 2017
nope , it returns false
( iam using a raspberry pi zero with latest raspbian and python3 , with pillow installed with pip3)
wiredfool commentedon Jul 17, 2017
I've got it leaking in Py3.5, in 4.1.0 and 4.2.1, though the location in 4.1.0 seems off. Similar leak sizes, but not the same. OTOH, I'm not on ARM, so that's not unexpected.
gompa commentedon Jul 17, 2017
on 4.1.1 py3.4 i can get it to leak in /usr/local/lib/python3.4/dist-packages/PIL/ImageDraw.py:222
moving the following into the loop does not seem to help either (i thought maybe it was because of the object not being removed
wiredfool commentedon Jul 17, 2017
I think what's going on here is in _imaging.c, around line 2170
PyUnicode_AsLatin1Stringreturns a new reference, which is then used byPyBytes_AsStringto give us a char* pointer. But it's never freed, it's just dropped. It can't be freed here, because it needs to live as long as the text pointer is alive.This code is likely the root of #2620 as well, as it's common to both code paths and it's the only place latin1 is mentioned.Fix for memory leak in PILfont _font_text_asBytes, python-pillow#2629
Fix for truetype memory leak, python-pillow#2629
wiredfool commentedon Jul 18, 2017
And similarly, in text_layout_*,
glyph_info is returned, but never freed by the caller.
Fix for memory leak in PILfont _font_text_asBytes, python-pillow#2629
Fix for truetype memory leak, python-pillow#2629
Fix for memory leak in PILfont _font_text_asBytes, python-pillow#2629
Fix for truetype memory leak, python-pillow#2629