[pygtk] Memory leak when using pangocairo for animation

Seth Remington sremington at saberlogic.com
Tue Sep 30 21:28:51 WST 2008


Hello,

I am not a member of the list but can confirm the OP's discovery of the
memory leak. I was Googling for this and found this mailing list post
and then noticed that the date was only three days ago (thanks for the
quick indexing Google) and thought I should chime in.

I have a custom cairo widget inheriting from a gtk.DrawingArea that
displays some text and refreshes very frequently. Using cairo's built-in
text rendering (i.e. show_text()) I do not see the memory leak but when
I switched to using pangocairo then I saw the massive memory growth.

Here's the code snipets:

NO MEMORY LEAK
==============
context.select_font_face('sans-serif')
context.set_font_size(20)
loop_name = str(self.loop.loop_number + 1)
(x, y, text_width, text_height, dx, dy) = context.text_extents(loop_name)
context.move_to(2, text_height + 2)
context.set_source_rgb(0.9, 0.9, 0.9)
context.show_text(loop_name)

MEMORY LEAK
===========
font = "Sans Serif 20"
markup = "<span font_desc='%s'><b>%d</b></span>" % (font, self.loop.loop_number + 1)
pango_context = pangocairo.CairoContext(context)
layout = pango_context.create_layout()
layout.set_markup(markup)
layout.set_alignment(pango.ALIGN_LEFT)
context.move_to(2, 2)
context.set_source_rgb(0.9, 0.9, 0.9)
pango_context.show_layout(layout)

-Seth


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________


More information about the pygtk mailing list