I am using the latest version of the PyGTK All-in-One installer (2.24.2) for Python 2.7, which includes Cairo 1.10.8, Pango 1.29.4, PyGTK 2.24.0 and PyGobject 2.28.3 (I think).
The following leak code is ~ 55 MB of memory:
import gtk window = gtk.Window() label = gtk.Label() window.add(label) window.show_all() for _ in range(100000): label.set_markup('Leaking memory!') while gtk.events_pending(): gtk.main_iteration()
Note. The for loop is in my test script so that I can see the increase in memory consumption in the task manager. It is also essential what happens in my real application, except that the text of the label changes at least once per second, and not just redrawn with the same text every time.
The problematic line is label.set_markup() , which runs around 0.5 kB per call, so I suspect the problem is in GTK or Cairo somewhere. Perhaps this error (685959) , as noted by the commentator.
I tried using objgraph to see if any additional Python objects are displayed in proportion to the number of calls to gtk.Label.set_markup() , but there are no extra objects. It follows that calling gc.collect() does not help, and I tried to do this. Python does not seem to be aware of objects that are responsible for memory consumption.
How can I find a memory leak and / or work around it? I need to use markup to style some text for this application, but I tried using gtk.Label.set_text() as a workaround, and it also loses memory.
I should note that this application is for Windows, so using PyGObject to get GTK 3 is not an option - GObject introspection is still not available on Windows.
source share