是否有可接受的内存泄漏限制? [英] Is there an acceptable limit for memory leaks?

查看:138
本文介绍了是否有可接受的内存泄漏限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始在C ++中尝试使用SDL,我认为定期检查内存泄漏可能是早期形成的好习惯。



考虑到这一点,我一直通过Valgrind运行我的Hello world程序来捕获任何泄漏,虽然我已经删除了除了最基本的 SDL_Init() SDL_Quit()语句,Valgrind仍然报告120字节丢失和77k仍然可达。



我的问题是:是否有可接受的内存泄漏限制,或者我应该努力使我的所有代码完全无泄漏?

解决方案

请注意,Valgrind不会在测量中拾取误报。



很多天真的内存分析器的实现标志着丢失的内存作为一个泄漏,当它不是真的。



也许读一些论文维基百科中关于Purify的文章的外部链接部分。我知道Purify附带的文档描述了几个场景,当你尝试检测内存泄漏时,你会得到假阳性,然后继续描述Purify用来解决问题的技术。



BTW我不以任何方式隶属于IBM。我只是广泛使用Purify,并会保证其有效性。



编辑:这里有一个优秀介绍性文章,涵盖内存监控。它是Purify特定的,但是关于内存错误类型的讨论是非常有趣的。



HTH。



/ p>

Rob


I've just started experimenting with SDL in C++, and I thought checking for memory leaks regularly may be a good habit to form early on.

With this in mind, I've been running my 'Hello world' programs through Valgrind to catch any leaks, and although I've removed everything except the most basic SDL_Init() and SDL_Quit() statements, Valgrind still reports 120 bytes lost and 77k still reachable.

My question is: Is there an acceptable limit for memory leaks, or should I strive to make all my code completely leak-free?

解决方案

Be careful that Valgrind isn't picking up false positives in its measurements.

Many naive implementations of memory analyzers flag lost memory as a leak when it isn't really.

Maybe have a read of some of the papers in the external links section of the Wikipedia article on Purify. I know that the documentation that comes with Purify describes several scenarios where you get false positives when trying to detect memory leaks and then goes on to describe the techniques Purify uses to get around the issues.

BTW I'm not affiliated with IBM in any way. I've just used Purify extensively and will vouch for its effectiveness.

Edit: Here's an excellent introductory article covering memory monitoring. It's Purify specific but the discussion on types of memory errors is very interesting.

HTH.

cheers,

Rob

这篇关于是否有可接受的内存泄漏限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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