原理和简介
Valgrind follows each allocation in your program and tracks it to see if it is returned properly, continue to be referenced or is lost in space, which is a ‘memory leak’. And as any leak, given enough time you will drown, in this case require more and more memory, until either you program is eating up your whole computer, or you get out of memory.
常用 memcheck
--tool=memcheck
是默认选项
valgrind --leak-check=yes YourRunCommand
valgrind --leak-check=full YourRunCommand
其他工具:多线程竞争halgrind
,缓存misscachegrind
配合gdb
gdb可以停在valgrind的error处,此时你可以通过gdb来观察现场
https://www.responsive.se/thomas/2013/09/20/debugging-memory-leaks-with-valgrind-and-gdb/