Valgrind 可能丢失了记忆 [英] Valgrind possibly lost memory
问题描述
当使用 --leak-check=full
运行 valgrind 时,生成的报告包含有关可能丢失"的内存的信息.
When running valgrind with --leak-check=full
the generated reports include information about memory "possibly lost".
valgrind 手册中有一些关于此的信息,以及一些示例报告.
There is some information on this in the valgrind manual, as well as some example reports.
http://valgrind.org/docs/manual/mc-manual.html
LEAK SUMMARY:
definitely lost: 4 bytes in 1 blocks
indirectly lost: 0 bytes in 0 blocks
possibly lost: 0 bytes in 0 blocks
still reachable: 95 bytes in 6 blocks
of which reachable via heuristic:
stdstring : 56 bytes in 2 blocks
length64 : 16 bytes in 1 blocks
newarray : 7 bytes in 1 blocks
multipleinheritance: 8 bytes in 1 blocks
suppressed: 0 bytes in 0 blocks
在我自己的系统中,当我使用 valgrind 执行我的多线程测试二进制文件时,我得到了大量可能"丢失的内存.
In my own system, i get plenty of "possibly" lost memory when executing my multi-threaded test binary with valgrind.
valgrind 报告内存可能丢失"究竟是什么意思?在这次特定的执行中,它是丢失了还是没有丢失.在我看来,内存泄漏应该比可能丢失"更黑白分明.
What exactly does it mean that valgrind reports memory as "possibly lost"? Was it lost or wasn't it in this particular execution. Memory leakage should be more black and white than "possibly lost" in my opinion.
推荐答案
大致的类别是
- 仍在使用 = 在退出时有一个指向内存的活指针
- 绝对丢失 = 没有指向内存的实时指针
- 间接丢失 = 有指向内存的指针,但指针本身在绝对丢失"的内存中.
- 可能丢失 = 有一个指针但不是内存的开始.
Valgrind 检测到可能丢失的主要原因是
The main reasons that Valgrind will detect possibly lost are either
- 一些不小心指向块的垃圾指针.您应该将此视为明确的损失.
- 分配子块或保护带的内存管理器.
因此,通常情况下,如果您没有使用内存管理器,请将可能的损失视为确定的损失.
So as a rule, if you are not using a memory manager, consider your possible losses as definite ones.
这篇关于Valgrind 可能丢失了记忆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!