我感觉我的程序有内存泄露,但是为什么valgrind检测结果每次都是OK的呢?
程序test运行大约一天左右,在所有业务流程已经终止情况下,通过ps命令查询结果如下:
PID TTY STAT TIME MAJFL TRS DRS RSS %MEM COMMAND
2286 pts/0 S 0:00 1 50 163793 40604 2.3 test
我记得刚启动的时候%MEN列是0.4的,另外再过一天左右这个数值会变成大约5.0,因此我感觉此程序有内存泄露(也不知道我的这个土方法对不对哈)。
网上查的说valgrind很管用,下载安装后查询结果如下,居然只说有16字节的泄露,而且这个还是glib启动时创建的loop,本身就是不释放,到底是valgrind有问题还是我的参数方法不对,请高手指点,谢谢
/usr/local/webserver/valgrind/bin/valgrind --tool=memcheck --leak-check=full ./test
==15972== Memcheck, a memory error detector.
==15972== Copyright (C) 2002-2008, and GNU GPL'd, by Julian Seward et al.
==15972== Using LibVEX rev 1884, a library for dynamic binary translation.
==15972== Copyright (C) 2004-2008, and GNU GPL'd, by OpenWorks LLP.
==15972== Using valgrind-3.4.1, a dynamic binary instrumentation framework.
==15972== Copyright (C) 2000-2008, and GNU GPL'd, by Julian Seward et al.
==15972== For more details, rerun with: -v
==15972==
==15972== 16 bytes in 1 blocks are definitely lost in loss record 1 of 3
==15972== at 0x4A050CC: calloc (vg_replace_malloc.c:397)
==15972== by 0x4C59CB2: g_malloc0 (gmem.c:151)
==15972== by 0x4C53569: g_main_loop_new (gmain.c:2869)
==15972== by 0x4083D8: main (test.c:518)
==15972==
==15972== LEAK SUMMARY:
==15972== definitely lost: 16 bytes in 1 blocks.
==15972== possibly lost: 0 bytes in 0 blocks.
==15972== still reachable: 4,460 bytes in 9 blocks.
==15972== suppressed: 0 bytes in 0 blocks.
==15972== Reachable blocks (those to which a pointer was found) are not shown.
==15972== To see them, rerun with: --leak-check=full --show-reachable=yes