如何使用 Valgrind 确定内存泄漏"still-available"来源?
How can I use Valgrind to determine the source of "still-available" memory leak?
我有一个我写的程序,它的内存足迹会随着时间的推移而增长。它最终消耗了所有可用的系统内存,然后崩溃了系统。
我正在尝试确定似乎内存泄漏的来源。我已经在代码上运行valgrind。它不确定或间接丢失记忆。它确实列出了可能会丢失的记忆,但没有太大的清晰度。我可以使用一些有关如何跟踪此问题的建议。
==13049== HEAP SUMMARY:
==13049== in use at exit: 2,240,095 bytes in 3,720 blocks
==13049== total heap usage: 50,296 allocs, 46,576 frees, 768,607,751 bytes allocated
==13049==
==13049== Searching for pointers to 3,720 not-freed blocks
==13049== Checked 56,807,736 bytes
==13049==
==13049== Thread 1:
==13049== 64 bytes in 4 blocks are possibly lost in loss record 1 of 11
==13049== at 0x4844F70: malloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==13049==
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:malloc
}
==13049== 184 bytes in 1 blocks are possibly lost in loss record 2 of 11
==13049== at 0x48472C4: realloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==13049==
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:realloc
}
==13049== 520 bytes in 20 blocks are possibly lost in loss record 3 of 11
==13049== at 0x48473FC: memalign (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==13049==
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:memalign
}
==13049== 643 bytes in 11 blocks are still reachable in loss record 4 of 11
==13049== at 0x4845DFC: operator new[](unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==13049==
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: reachable
fun:_Znam
}
==13049== 944 bytes in 47 blocks are still reachable in loss record 5 of 11
==13049== at 0x4844F70: malloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==13049==
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: reachable
fun:malloc
}
==13049== 3,408 bytes in 19 blocks are possibly lost in loss record 6 of 11
==13049== at 0x48470CC: calloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==13049==
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: possible
fun:calloc
}
==13049== 5,056 bytes in 7 blocks are still reachable in loss record 7 of 11
==13049== at 0x48472C4: realloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==13049==
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: reachable
fun:realloc
}
==13049== 37,304 bytes in 185 blocks are still reachable in loss record 8 of 11
==13049== at 0x48470CC: calloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==13049==
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: reachable
fun:calloc
}
==13049== 97,782 bytes in 1,739 blocks are still reachable in loss record 9 of 11
==13049== at 0x48456C8: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==13049==
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: reachable
fun:_Znwm
}
==13049== 124,585 bytes in 1,666 blocks are still reachable in loss record 10 of 11
==13049== at 0x4845040: malloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==13049==
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: reachable
fun:malloc
}
==13049== 1,969,605 bytes in 21 blocks are still reachable in loss record 11 of 11
==13049== at 0x48473FC: memalign (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so)
==13049==
{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: reachable
fun:memalign
}
==13049== LEAK SUMMARY:
==13049== definitely lost: 0 bytes in 0 blocks
==13049== indirectly lost: 0 bytes in 0 blocks
==13049== possibly lost: 4,176 bytes in 44 blocks
==13049== still reachable: 2,235,919 bytes in 3,676 blocks
==13049== of which reachable via heuristic:
==13049== newarray : 1,536 bytes in 16 blocks
==13049== suppressed: 0 bytes in 0 blocks
valgrind被调用:
valgrind --child-silent-after-fork=yes --smc-check=stack --tool=memcheck --gen-suppressions=all --track-origins=yes --leak-check=full --num-callers=500 --leak-check=full --show-leak-kinds=all -v --show-reachable=yes /opt/fsoapp/bin/fsoapp
使用选项
--leak-check=full --show-leak-kinds=all
在您的程序终止时获取仍然可及的内存列表。
您还可以使用GDB VGDB和Valgrind进行交互式搜索泄漏。请参阅http://www.valgrind.org/docs/manual/mc-manual.html#mc-manual.monitor-commands
特别是,监视器命令" block_list"answers" who_points_at"可以帮助查找保留内存的位置。
相关文章:
- 为什么 boost::asio::ip::tcp::basic_stream_socket::available 的运行
- 在瓦尔格林德的泄漏摘要中使用 std::ios::sync_with_stdio(fasle) 打印时获取"still reachable"
- QT "relocation error" / "no version information available"运行时错误
- 如何在 Arduino 延迟期间在 void loop() 中使用 serial.available()?
- Windows 10 环境中的"This version of XAudio2 is available only in Windows 8"错误
- 我的模板二叉搜索树类给出了错误"Node<T>: no appropriate default constructor available,"如何解决这个问题?
- 如何使用 Valgrind 确定内存泄漏"still-available"来源?
- C++ 模板:'Instantiation of variable required here, but no definition is available'
- 平息海湾合作委员会的"only available with -std=c++XX or -std=gnu++XX"警告
- git_remote_fetch返回错误并显示消息:"there is no TLS stream available"
- WxWidgets Hello World 编译失败:"wchar_t must be available"
- C++派生类的"no appropriate default constructor available"
- Arduino serial.available奇怪的错误
- Linux C++中的 UVC Camera "Still Pin" 捕获
- 是一个常量字符串Still Preferrable
- 逻辑帮助:比较值并取最小距离,同时将其从"available to compare"列表中删除
- 设置返回值时忽略"still reachable"
- Arduino Serial.available() 不断增加
- "No appropriate default constructor available"在C++11
- C++ make_shared not available