且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否有可接受的内存泄漏限制?

更新时间:2023-09-06 14:25:16

请注意,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