views:

29

answers:

1

Whenever I load any GTK+-powered application in valgrind, it reports a lot of memory leaks. What's up with that? Is GTK+ buggy?

+1  A: 

GTK+ and GLib don't free "allocate once" memory. They follow the paradigm that says it is unnecessary to free resources just before the process exits that will be freed by the system anyway (this mostly applies to memory). This is of course not quite debugging-friendly, but allows to speed up program termination a bit and simplify the code (this is C, even "trivial" tasks take lines to code).

So, "still reachable" memory is most likely just not freed intentionally, and not a leak. Or, of course, might be a bug. "Definitely lost" memory, however, is almost certainly a bug.

Also note that program's memory leaking bugs can look as if they are triggered by GTK+ itself. For instance, GTK+ might allocate an object to be dereferenced (and freed) later by the program, which fails to do so. Valgrind will show a stack trace deep in GTK+, despite the bug being in the program.

doublep