GNOME Bugzilla – Bug 599730
Memory leak in pangocairo.CairoContext.create_layout()
Last modified: 2018-08-17 13:42: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
Thanks for the report, I committed a fix.
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
Confirmed with pycairo 1.8.10, pygobject 2.28 and pygtk 2.24.
This bug still exists in my up-to-date archlinux box.
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)
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!