开发者

What's up with GTK+ windows having so many memory leaks according to Valgrind?

Whenever I load any GTK+-powered application in valgrind, it reports a lot o开发者_如何学Cf memory leaks. What's up with that? Is GTK+ buggy?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜