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

查看:93
本文介绍了在c ++中检查内存泄漏的最好方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用链接列表实现稀疏矩阵,手动检查泄漏和任何想法是没有乐趣的。

I'm implementing a sparse matrix with linked lists and it's not fun to manually check for leaks, any thoughts?

推荐答案

valgrind profiler for 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天全站免登陆