valgrind 报告未释放的块
Valgrind 泄漏文件摘要:
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
malloc/free: in use at exit: 45,065 bytes in 12 blocks.
malloc/free: 161 allocs, 149 frees, 53,301 bytes allocated.
searching for pointers to 12 not-freed blocks.
checked 583,764 bytes.
这 12 个块之一来自 strdup
。我同意,我应该释放 strdup 分配的东西。
我的问题是,一般来说,留下未释放的块是否不好?从技术上讲它被称为mem-leak吗?
一旦程序终止,它们不会返回给系统吗?
请指教。
编辑0:感谢您的回复。我怎么知道这 12 个未释放的块在哪里?代码的哪一部分生成它们?
Valgrind leak file summary:
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
malloc/free: in use at exit: 45,065 bytes in 12 blocks.
malloc/free: 161 allocs, 149 frees, 53,301 bytes allocated.
searching for pointers to 12 not-freed blocks.
checked 583,764 bytes.
One of this 12 blocks is from strdup
. I should have freed things allocated by strdup, I agree.
My question is, in general, is it bad to leave non-freed blocks? Is it called mem-leak technically?
Are they not given back to the system once program dies?
Please advise.
Edit 0: Thanks for your responses. How can I know where are these 12 non-freed blocks? And what part of code is generating them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它被返回给系统。
如果您有对内存的引用,那么从技术上讲,这并不是内存泄漏。要发生内存泄漏,您必须取消引用内存。
任何时候留下未释放的块都是不好的。如果程序正在完成它,它可能并没有那么糟糕,但对于您将来可能做的任何更改都不利(例如:提取一个函数并多次调用它)。
此外,消除所有内存泄漏将使使用 valgrind 更容易跟踪任何新的(和相关的)内存泄漏。
It is given back to the system.
It it not technically a memory leak if you have a reference to the memory. To be a memory leak you must de-reference the memory.
It is bad to leave non-freed blocks at any point. If the program is finishing it, it might not be that bad, but it is not good for any future change you might do (e.g.: extract a function and call it multiple times).
Also, getting rid of all memory leaks will make it easier to track with valgrind any new (and relevant) one.
是的,留下未释放的块是不好的。这称为内存泄漏。如果您允许它,您的程序最终将使用系统中的所有可用内存。
程序终止后,程序分配的内存将被释放。
Yes, it is bad to leave non-freed blocks. It's called memory-leak. If you let it your program will eventually use all available memory in your system.
After program dies memory allocated by your program is freed.