Valgrind检测到琐碎代码的未列出的堆内存使用
Valgrind detects unfreed heap memory usage for a trivial code
我的valgrind告诉我,它为最琐碎的C 代码找到了非填充的内存。
我的代码显示如下:
#include <iostream>
#include <string>
int main() {
std::cout << "Hello!!!!" << std::endl;
return 0;
}
,Valgrind的结果在这里:
==12455== HEAP SUMMARY:
==12455== in use at exit: 72,704 bytes in 1 blocks
==12455== total heap usage: 2 allocs, 1 frees, 73,728 bytes allocated
==12455==
==12455== 72,704 bytes in 1 blocks are still reachable in loss record 1 of 1
==12455== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==12455== by 0x4EC3EFF: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21)
==12455== by 0x40106C9: call_init.part.0 (dl-init.c:72)
==12455== by 0x40107DA: call_init (dl-init.c:30)
==12455== by 0x40107DA: _dl_init (dl-init.c:120)
==12455== by 0x4000C69: ??? (in /lib/x86_64-linux-gnu/ld-2.23.so)
==12455==
==12455== LEAK SUMMARY:
==12455== definitely lost: 0 bytes in 0 blocks
==12455== indirectly lost: 0 bytes in 0 blocks
==12455== possibly lost: 0 bytes in 0 blocks
==12455== still reachable: 72,704 bytes in 1 blocks
==12455== suppressed: 0 bytes in 0 blocks
==12455==
==12455== For counts of detected and suppressed errors, rerun with: -v
==12455== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
这是Valgrind的错误?
这是由于C 标准库的工作方式。这些容器分配了大量内存(称为池(并在内部进行管理。他们基本上使用了自己的内存管理器,而不是依靠系统的内存管理器。因此,当对象被破坏时,它的内存将被内部分配器释放以重复使用,但没有回到操作系统。
这也在Valgrind的常见问题中描述。
要概括一些,valgrind是一个非常有用的工具,但您不应瞄准0泄漏,而是要理解其报告并找到表示代码中问题的泄漏。
我在ubuntu 19.04下使用valgrind 3.14.0,我没有得到任何检测。我用--leak-check=full
跑了,没有。也许是Valgrind的一些版本。
相关文章:
- Constexpr替代了新的放置方式,可以让内存中的对象保持未初始化状态
- 使用 g++7 构建的代码在访问未对齐的内存时崩溃
- 内存清理程序报告全局对象构造中未初始化值的使用
- 如何删除列出的"QGraphicsPathItem"对象以控制进程内存使用情况?
- 内存未释放 std::list<std::shared_ptr<std::string>> C++
- 有没有办法列出所有共享内存对象的名称?
- 如果操作系统未清除内存泄漏,则在程序完成后内存泄漏是否仍然存在?
- Valgrind检测到琐碎代码的未列出的堆内存使用
- 列出当前过程并使用未记录的当前功能编写内存的软件技巧
- C++动态变量和未定义内存之间的差异
- malloc未分配内存
- 终端中未显示内存地址(参考)
- Visual Studio 版本之间的不同未分配内存行为
- 是否允许枚举具有未列出的值
- Qt 4.8.0 - MySQL驱动程序未列出
- 为什么我要获得未分配内存的读写权限?
- 如何在C++中检测未分配内存上的双重删除或删除
- 将移动构造函数自动初始化未列出的成员
- 联合中未使用内存的内容是什么?
- Make_pair of std::map -如何仅在键未列出时生成一对(否则更新键)