Memory Leaks in GTK hello_world program

前端 未结 2 610
别跟我提以往
别跟我提以往 2020-12-04 01:49

So... I\'m trying to eliminate some memory leaks from my GTK+ 3 program. I though it would be a good idea to look back at some simple examples to see if there is some cleanu

2条回答
  •  天涯浪人
    2020-12-04 02:00

    For debugging glib/gtk programs I would use this command:

    G_SLICE=debug-blocks valgrind --tool=memcheck --leak-check=full 
    

    G_SLICE=debug-blocks will turn off gtk's advanced memory management to allow valgrind to show correct results.

    --leak-check=full will show stack traces for the leaked memory blocks.

    You can also use --show-reachable=yes to see stack traces for all memory blocks that haven't been free when the program exits.

    There is also the massif valgrind tool that tracks memory usage to show which parts of the program are using the most memory.

    Run program under massif:

    G_SLICE=always-malloc valgrind --tool=massif --detailed-freq=2 --max-snapshots=400 --num-callers=20 
    

    Show results:

    ms_print massif.out.
    

提交回复
热议问题