What is the best way to check for memory leaks in c++?(在 C++ 中检查内存泄漏的最佳方法是什么?)
问题描述
我正在实现一个带有链表的稀疏矩阵,手动检查泄漏并不好玩,有什么想法吗?
I'm implementing a sparse matrix with linked lists and it's not fun to manually check for leaks, any thoughts?
推荐答案
valgrind
用于 Unix 的分析器提供了不错的泄漏检测.
The valgrind
profiler for Unix offers a decent leak detection.
然而,这只是成功方法的一部分.另一部分是防止(即最小化)显式内存处理.智能指针和分配器可以在很大程度上帮助防止内存泄漏.此外,确实使用 STL 类:std::list
已经提供了无泄漏链表实现.
However, this is only one part of a successful approach. The other part is to prevent (i.e. minimize) explicit memory handling. Smart pointers and allocators can help a great deal in preventing memory leaks. Also, do use the STL classes: a leak-free linked list implementation is already provided by std::list
.
这篇关于在 C++ 中检查内存泄漏的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C++ 中检查内存泄漏的最佳方法是什么?


- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 近似搜索的工作原理 2021-01-01
- C++ 协变模板 2021-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 静态初始化顺序失败 2022-01-01
- 从python回调到c++的选项 2022-11-16
- Stroustrup 的 Simple_window.h 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- STL 中有 dereference_iterator 吗? 2022-01-01