Memory Leaks in GTK hello_world program

This answer is compiled from answers to the same question (on the now defunct www.gtkforums.com).

GTK+ is pretty lazy when it comes to allocating and deallocating internal buffers needed for the life time of the application. For example it may allocate an area of memory for a lookup table during initialisation which is needed for the life of the application. GTK+ will then never deallocate this. To Valgrind this looks like a memory leak, (which technically it is) but as an optimisation GTK+ does not deallocate it as it will be deallocated during application exit and so not an error. This is why you need suppression files so that Valgrind can ignore these. The problem is that you will need to change these with most GTK+ version changes.

Repository of suppression files:
https://github.com/dtrebbien/GNOME.supp

After cloning the repository, you can generate the suppression files (also comes with glib, gdk, and others) with “make” and then refer valgrind to them like so:

valgrind ./a --suppression=/path/to/gtk3.supp

Leave a Comment