我已经在小程序中使用 Valgrind
来检查 内存泄漏
并且它的工作很好。
现在我有一个包含许多类和 .cpp
和 .h
文件的大程序,我正在尝试使用 Valgrind
来检查内存泄漏
因为我使用了很多指针、内存等。
我正在使用 linux
和 codeblocks 16.01
以及 gcc
并且我试图直接运行 Valgrind
codeblocks
但我收到以下错误:
--------------- Application output --------------
valgrind: /myPathToTheProject/ValgrindOut.xml: No such file or directory
如果我用一个只有 .cpp
文件和 main 的小项目进行测试,它运行良好并且 Valgrind
生成 ValgrindOut.xml
.在这个大项目中,我总是遇到这个错误。有人知道出了什么问题吗?或其他方法或工具来测试内存泄漏
?
编辑 - 运行 Valgrind 后的泄漏摘要
Leak summary:
definitely lost: 673 bytes in 6 blocks.
indirectly lost: 89,128 bytes in 68 blocks.
possibly lost: 232 bytes in 2 blocks.
still reachable: 80,944 bytes in 6 blocks.
suppressed: 0 bytes in 0 blocks.
最佳答案
我不确定如何直接从代码块运行 valgrind。我建议您使用代码块构建项目。执行时,按照以下命令使用 valgrind。
命令
valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all --log-file=leak.txt ./myexecutable <my command line arguments>
例子
valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all --log-file=leak.txt ./myexecutable -i 192.168.1.10 -p 5000
这样就可以生成valgrind的输出文件,即包含内存泄漏等的leak.txt
关于c++ - 代码块上的 Valgrind (linux),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45435290/