超嚴重 memory leak
怎麼想也想不通,為甚麼用 GTK+ 的程式會變得那麼恐佈。兩三天前試寫一個空白的 GTK+ window,然後用 valgrind 檢查一下(萬分感謝 valgrind),肯定的 memory leak 是 0 byte,但只要隨便加一個 widget 上去,情況就失控了:
| 沒有 widget | 0 byte |
|---|---|
| 加一個 vbox | 0 byte |
| 再加一個 statusbar | 131KB (!) |
| 不加 statusbar,改為加 notebook 和加一個空白 page | 62KB |
| 再加回 statusbar | 131KB |
| 再加 button box,其中有一個 button | 131KB |
註:只計算 “definitely lost” 和 “indirectly lost” 的部份。
嚇一跳之後,定一定神,使用 valgrind 的 --leak-check=full 選項,發現不約而同地,每種情況都大約有 99.5% memory leak 是來自 fontconfig 的。似乎任何會觸碰到 pango 的 widget 都會引致同一結果:
132,396 (39,680 direct, 92,716 indirect) bytes in 154 blocks are definitely lost in loss record 160 of 166
at 0x402071B: realloc (vg_replace_malloc.c:306)
by 0x45C6253: (within /usr/lib/libfontconfig.so.1.2.0)
by 0x45C6C06: (within /usr/lib/libfontconfig.so.1.2.0)
by 0x45C70FB: (within /usr/lib/libfontconfig.so.1.2.0)
by 0x45C3892: FcFontRenderPrepare (in /usr/lib/libfontconfig.so.1.2.0)
by 0x49CF7E2: (within /usr/lib/libpangoft2-1.0.so.0.1600.2)
by 0x462625F: pango_font_map_load_fontset (in /usr/lib/libpango-1.0.so.0.1600.2)
by 0x4624206: (within /usr/lib/libpango-1.0.so.0.1600.2)
by 0x4624591: pango_itemize_with_base_dir (in /usr/lib/libpango-1.0.so.0.1600.2)
by 0x462CA1A: (within /usr/lib/libpango-1.0.so.0.1600.2)
by 0x462D646: (within /usr/lib/libpango-1.0.so.0.1600.2)
by 0x418398F: gtk_label_size_request (gtklabel.c:2117)
現在還不知道是否我做漏了甚麼事情。真是想不通。但這樣下去,每次 130 KB,有多少 RAM 夠我用呀?
Are you sure it’s a real leak? Valgrind signals false positives all the time…
I can’t be really sure — but reporting so much memory as false positive is still quite alarming.
Is there any better tools to determine if it’s genuine memory leak?
RTFS would be the best XD
係喎,我發覺個pidgin用咗我成百幾mb ram……