After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 625287 - memory leak while rendering text
memory leak while rendering text
Status: RESOLVED DUPLICATE of bug 674092
Product: pygtk
Classification: Bindings
Component: pango
2.16.x
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2010-07-26 08:42 UTC by Claudio Cilloni
Modified: 2013-04-05 18:15 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Claudio Cilloni 2010-07-26 08:42:56 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.
Comment 1 Aldo Cortesi 2010-11-04 23:36:47 UTC
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()
Comment 2 Aldo Cortesi 2010-11-04 23:43:12 UTC
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.
Comment 3 eurleif 2011-12-26 05:16:27 UTC
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)
Comment 4 Federico Mena Quintero 2013-04-05 18:15:06 UTC

*** This bug has been marked as a duplicate of bug 674092 ***