Sorry, your browser cannot access this site
This page requires browser support (enable) JavaScript
Learn more >

原理和简介

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

https://tutorialadda.com/gdb/what-is-valgrind-and-how-to-debug-memory-related-issue-using-valgrind#:~:text=Valgrind%20is%20a%20debugging%20tool%20used%20for%20memory,to%20optimize%20memory%20uses%20during%20running%20the%20program.

其他工具:多线程竞争halgrind,缓存misscachegrind

配合gdb

gdb可以停在valgrind的error处,此时你可以通过gdb来观察现场
https://www.responsive.se/thomas/2013/09/20/debugging-memory-leaks-with-valgrind-and-gdb/

评论