GNOME Bugzilla – Bug 625287
memory leak while rendering text
Last modified: 2013-04-05 18:15:06 UTC
I'm getting some memory leaks in my application while rendering text. This is a test case: -------------------------------------------------------------------- import sys, os, gc import pango import cairo import pangocairo if __name__ == '__main__': surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 400, 300) cr = pangocairo.CairoContext(cairo.Context(surface)) cr.set_source_rgb(1.0, 0.0, 0.0) for i in xrange(500000): cr.new_path() cr.move_to(100, 100) layout = cr.create_layout() layout.set_text('text text text') cr.show_layout(layout) -------------------------------------------------------------------- running this python program, I see the process virtual memory size grow while the number of python objects remains constant (shown by adding 'print len(gc.get_objects())' inside the loop). The only object created inside the loop is the layout. Could this be a bug inside PangoLayout class? I'm running python-2.6.4, pycairo-1.8.8, cairo-1.8.8, pango-1.26.2, pygtk-2.16.0 thank you for your support.
This is still present in a current git checkout. The leak seems to be in create_layout - the following simplified program also demonstrates the problem: #!/usr/bin/env python import sys, os, gc import pango import cairo import pangocairo surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 100, 100) cr = pangocairo.CairoContext(cairo.Context(surface)) for i in xrange(500000): layout = cr.create_layout()
For what it's worth, this is a high-priority bug for us. We've recently moved qtile, a small, hackable Python window manager to Pango for text layouts - the results are very pretty, but this bug slays us.
The memory leak appears to be in caused by the create_layout() method. I've successfully worked around it by creating the layout manually: def create_layout(context): fmap = pangocairo.cairo_font_map_get_default() pangoctx = fmap.create_context() context.update_context(pangoctx) return pango.Layout(pangoctx)
*** This bug has been marked as a duplicate of bug 674092 ***