Fork me on GitHub

cuspy memo


glib のメモリリーク疑惑

2007/07/19 Thursday 02:16:25

glib の g_string() を使用したときに mtrace してみるとメモリリークしているように見える。

mtrace();
str = g_string_new("hoge");
g_string_free(str, FALSE);
muntrace();

上記のような単純なコードでも

Memory not freed:
—————–
Address Size Caller
0×0804a378 0×34 at 0xb7fa0095
0×0804a3b8 0×8 at 0xb7fa0095
0×0804a3c8 0×400 at 0xb7fa0095
0×0804a7d0 0×34 at 0xb7fa0095
0×0804a810 0×400 at 0xb7fa0095

ほらこんな感じ。

調べてみると同じような話題が ML で見つかった。

http://mail.gnome.org/archives/gtk-list/2004-September/msg00050.html

http://mail.gnome.org/archives/gtk-list/2004-September/msg00051.html

What about running g_print in a loop? Note that many g_ functions have static overhead that often show up as a memory leak but they really don’t have leaks. IE they may claim some memory, but it is freed when the program quits and is not allocated every time the function is called.

たしかにこれはメモリリークでは無いという言い分も解るけど。
アプリケーション側のメモリリークと間違えたり紛らわしいのでライブラリでこういうのは止めて欲しいな。

No comments yet.

Leave a comment

You must be logged in to post a comment.