[pygtk] Memory leak when using pangocairo for animation

Kyle Schaffrick kyle at raidi.us
Fri Sep 26 13:54:37 WST 2008


Greetings,

I've isolated a fairly serious memory leak in an application I'm
writing, which involves using pangocairo and cairo to draw text and
graphics at moderately high update rates to produce an animated display.

I managed to create the attached minimal script which reproduces the
leak. It (the repro script) is kind of a hack, in that I'm using
gtk.main_iteration() to turn the main loop inside out, but the problem
originally/still appears when the drawing is initiated from timers in my
normally arranged event-driven application.

I have so far been unable to figure out what exactly is leaking (much
less how to fix it), but it seems to be related to high turnover of of
pango.Layout objects. I've tried using Python's GC debugging output and
Valgrind leakcheck and didn't see any smoking guns, but I'm by no means
a Valgrind wizard.

For a long running process that does this type of drawing (such as an
"realtime status display" sort of application, where I ran into this
leak), the process will continue to grow until VM thrashing and/or
OOM-killing occurs. With high-ish (16 Hz) update rates my Debian test
system with 192MB of physical RAM is completely incapacitated by
thrashing in a matter of 20-30 minutes or so.

I've reproduced this on two disparate systems so far. Does this
reproduce for anyone else, and/or does anyone see any obvious reason
that this script would hemorrhage memory? I'm stumped :)

-Kyle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pango-leak-demo.py
Type: text/x-python
Size: 1498 bytes
Desc: not available
Url : http://www.daa.com.au/pipermail/pygtk/attachments/20080926/5ea39422/attachment.py 


More information about the pygtk mailing list