c++ - 如何解释 Valgrind 输出

标签 c++ memory-leaks valgrind

Valgrind 生成以下消息 block :

1,065,024 bytes in 66,564 blocks are definitely lost in loss record 21 of 27
   at 0x4C2B800: operator new[](unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x40CA21: compute(Parameters&, Array<double>&) [clone .constprop.71] (array.hpp:135)
   by 0x403E70: main (main.cpp:374)

如何阅读这条消息?

main.cpp 第 374 行内容如下:

results[index] = compute(parameters, weights);

内存泄漏是否正好在 main.cpp 的第 374 行?它是在 compute() 中泄漏还是在分配/索引结果时泄漏?

最佳答案

Is memory leaked exactly at line 374 of main.cpp?

没有。它仅显示 main 中进行调用的行号,最终导致分配内存的函数和行。

Is it leaked in compute() or maybe at assignment/indexing into results?

它表示内存已在 compute() 中分配,但在程序退出之前未在程序中释放。这就是内存泄漏。

关于c++ - 如何解释 Valgrind 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30631133/

相关文章:

c++ - 尝试验证 C++ 中的输入

c++ - 如何访问碰撞的 assimp 模型数据?

c - 使用 htop 检测内存泄漏

c - 删除C中链表的第一个元素

multithreading - libCurl 真的是线程安全的吗?

g++ - 编译二进制文件以在 Snow Leopard 上使用 valgrind

c++ - 具有非类型模板参数的构造函数

c++ - 不正确的随机彩色矩形

C# 内存泄漏?

C - 内存泄漏故障排除