Linux記憶體洩漏檢查工具 valgrind

2021-06-01 08:44:15 字數 1259 閱讀 5916

valgrind工具功能很多,可以動態檢測程式執行時的問題,其中一項就是檢測記憶體洩漏。

使用方法: valgrind [options] prog-and-args

用例:問題程式**: memleak.c

#include #include main(int argc, char **argv)

執行程式: valgrind ./memleak

輸出結果:

==17823== memcheck, a memory error detector

==17823== command: ./memleak

==17823==

==17823==

==17823== heap summary:

==17823== in use at exit: 10 bytes in 1 blocks

==17823== total heap usage: 2 allocs, 1 frees, 15 bytes allocated

==17823==

==17823== leak summary:

==17823== definitely lost: 10 bytes in 1 blocks

==17823== indirectly lost: 0 bytes in 0 blocks

==17823== possibly lost: 0 bytes in 0 blocks

==17823== still reachable: 0 bytes in 0 blocks

==17823== suppressed: 0 bytes in 0 blocks

==17823== rerun with --leak-check=full to see details of leaked memory

==17823==

==17823== for counts of detected and suppressed errors, rerun with: -v

==17823== error summary: 0 errors from 0 contexts (suppressed: 12 from 7)

紅色字型部分顯示程式有兩次動態記憶體分配,共15個位元組,只free了一次,記憶體洩漏10個位元組

valgrind缺點:

目前好像只適用於gnu/linux x86平台

linux 記憶體洩漏檢查工具

sudo apt get install valgrind使用格式如下 valgrind tool memcheck 等一些開關指令 可執行檔名開關指令如下 tool memecheck 使用valgrind工具集中的memcheck工具 leak check full 完全full檢查記憶體洩漏 ...

VLD 記憶體洩漏檢查工具

1.安裝vld 2.5.1 2.配置依賴庫,工程新增路徑。additional include directories soup visual leak detector include additional depandencies soup visual leak detector lib wi...

記憶體洩漏檢查

1.乙個指標多次進行賦值時,每次賦值後使用完後要釋放記憶體 coffsetcoedgemap poffsetcoedgemap polygonoffset ppoly,retpolygon,doffsetdis,enextend,0.1 expect true g ovldmgr.isvalid r...