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 599730 - Memory leak in pangocairo.CairoContext.create_layout()
Memory leak in pangocairo.CairoContext.create_layout()
Status: RESOLVED WONTFIX
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
gnome[unmaintained]
Depends on:
Blocks:
 
 
Reported: 2009-10-27 06:12 UTC by marmuta
Modified: 2018-08-17 13:42 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
shortened valgrind log, valgrind --leak-check=full --num-callers=40 (39.07 KB, text/x-log)
2009-10-27 06:12 UTC, marmuta
Details

Description marmuta 2009-10-27 06:12:57 UTC
Created attachment 146317 [details]
shortened valgrind log, valgrind --leak-check=full --num-callers=40

While working on the onscreen keyboard onboard I noticed that font rendering
slowly eats up all available memory. I've tracked it to the call to
create_layout() in pangocairo.CairoContext. Apparently the returned layout
objects are never freed. I might be doing something wrong, but a fresh layout
object has a suspicious __grefcount__ of 2. Can that be right? 

Here is a minimal sample that rapidly takes up gigabytes of memory:

#! /usr/bin/env python
import cairo
import pangocairo
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 100, 100)
cr = pangocairo.CairoContext(cairo.Context(surface))
for i in range(10000000):
    layout = cr.create_layout()
surface.finish()

A corresponding minimal C program behaved well, so I suspect the python wrapper
somehow being involved.

Ubuntu 9.10 Karmic RC
python-gtk2 2.16.0-0ubuntu1
libpango1.0-0 1.26.0-1
libcairo2 1.8.8-2ubuntu1
Comment 1 Paul Pogonyshev 2009-10-31 20:52:14 UTC
Thanks for the report, I committed a fix.
Comment 2 marmuta 2011-04-23 09:30:03 UTC
Hi, this bug seems to be back. The above minimal test program rapidly eats up all memory and __grefcount__ of afresh layout object is again 2. Could you have a look?

Current Onboard bug report is here:
https://bugs.launchpad.net/pygtk/+bug/732179

Ubuntu 11.04 Natty
python-gtk2    2.22.0-0ubuntu1
libpango1.0-0  1.28.4-0ubuntu1
libcairo2 1.10.2-2ubuntu2
Comment 3 Dieter Verfaillie 2011-04-24 17:35:55 UTC
Confirmed with pycairo 1.8.10, pygobject 2.28 and pygtk 2.24.
Comment 4 Xinyu Zhou 2015-04-21 05:16:12 UTC
This bug still exists in my up-to-date archlinux box.
Comment 5 eurleif 2016-03-15 02:31:25 UTC
I've been using this function as a workaround. I call create_layout(context) instead of context.create_layout(), and it doesn't leak memory:

def create_layout(context):
    fmap = pangocairo.cairo_font_map_get_default()
    pangoctx = fmap.create_context()
    context.update_context(pangoctx)
    return pango.Layout(pangoctx)
Comment 6 André Klapper 2018-08-17 13:42:57 UTC
pygtk is not under active development anymore and had its last code changes
in 2013. Its codebase has been archived:
https://gitlab.gnome.org/Archive/pygtk/commits/master

PyGObject at https://gitlab.gnome.org/GNOME/pygobject is its successor. See https://pygobject.readthedocs.io/en/latest/guide/porting.html for porting info.

Closing this report as WONTFIX as part of Bugzilla Housekeeping to reflect
reality. Feel free to open a task in GNOME Gitlab if the issue described in this task still applies to a recent version of PyGObject. Thanks!