Working with a big memory leak in GTK when redrawing a shortcut

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.

+6
source share
1 answer

Error (685959) is really a problem. Bug fixed in gtk + 2.24.14. However, 2.24.14 will not compile for win32 (hopefully someone who reads my question and answer realizes that GTK is no longer a smart choice or cross-platform development).

I applied this patch to version 2.24.10 and successfully compiled the result. It seems to work with my new runtime files.

I used the instructions here to build GTK for Windows using MinGW: http://ingar.satgnu.net/devenv/mingw32/gtk.html

A 32-bit build will not work in the gtk-update-icon-cache cache unless you run the msys shell as an administrator. For a 64-bit build, you need rm gtk / gtk.def before running make. Create and install gtk + by running the following commands:

cd $ LOCALBUILDDIR & & \ wget -c http://ftp.gnome.org/pub/gnome/sources/gtk+/2.24/gtk+-2.24.10.tar.xz & & \ xz -d -c gtk + -2.24 .10.tar.xz | tar xv & & \ \ cd gtk + -2.24.10 && \. / configure --prefix = $ LOCALDESTDIR --with-gdktarget = win32 \ --with-included-immodules = ime --disable-debug --disable-gtk-doc && & & & \ make && & \ make install

I know this is not a “workaround” as I asked in my question, but for more than 6 months without an answer it tells me that there is no workaround other than fixing a runtime error ...

+1
source

Source: https://habr.com/ru/post/944247/


All Articles