在 C++ 中检查内存泄漏的最佳方法是什么? [英] What is the best way to check for memory leaks in c++?

查看:30
本文介绍了在 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++ 中检查内存泄漏的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆