是内存泄漏以往任何时候都好吗

是内存泄漏以往任何时候都好吗

本文介绍了是内存泄漏以往任何时候都好吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是以往任何时候都可以接受的一个在C或C ++应用程序?

Is it ever acceptable to have a memory leak in your C or C++ application?

如果您分配一些内存,并使用它,直到code在您的应用程序(例如,一个全局对象的析构函数),最后一行是什么?只要内存消耗不随时间增长,它是确定以信任OS释放你的内存为你当你的应用程序终止(在Windows,Mac和Linux)?你甚至可以考虑,如果是被持续使用的内存,直到它被释放操作系统这一个真正的内存泄漏。

What if you allocate some memory and use it until the very last line of code in your application (for example, a global object's destructor)? As long as the memory consumption doesn't grow over time, is it OK to trust the OS to free your memory for you when your application terminates (on Windows, Mac, and Linux)? Would you even consider this a real memory leak if the memory was being used continuously until it was freed by the OS.

如果一个第三方库强迫你这种情况呢?将拒绝使用第三方库无论多么伟大的它,否则可能是什么?

What if a third party library forced this situation on you? Would refuse to use that third party library no matter how great it otherwise might be?

我只看到一个实际的缺点,那就是这些良性的泄漏会显示内存泄漏检测工具误报。

I only see one practical disadvantage, and that is that these benign leaks will show up with memory leak detection tools as false positives.

推荐答案

没有。

作为专业人士,我们不应该问自己这样一个问题的问题,是它曾经确定要这样做吗?而是是否有过一个的的理由这样做呢?而追捕内存泄漏是一种痛苦是不是一个很好的理由。

As professionals, the question we should not be asking ourselves the question, "Is it ever OK to do this?" but rather "Is there ever a good reason to do this?" And "hunting down that memory leak is a pain" isn't a good reason.

我喜欢让事情变得简单。和简单的规则是,我的程序应该没有内存泄漏。

I like to keep things simple. And the simple rule is that my program should have no memory leaks.

这使我的生活简单,太。如果我发现了内存泄漏,我消灭它,而不是通过一些精心设计的决策树结构运行,以确定它是否是一个可接受的内存泄漏。

That makes my life simple, too. If I detect a memory leak, I eliminate it, rather than run through some elaborate decision tree structure to determine whether it's an "acceptable" memory leak.

它类似于编译器的警告 - 将警告是致命的到我的特殊应用?也许不会。

It's similar to compiler warnings – will the warning be fatal to my particular application? Maybe not.

但它的最终的职业纪律的问题。容忍编译器警告和容忍内存泄漏是个坏习惯,这将最终咬我的后面。

But it's ultimately a matter of professional discipline. Tolerating compiler warnings and tolerating memory leaks is a bad habit that will ultimately bite me in the rear.

要带的东西发挥到了极致,这将永远是可以接受的外科医生留下一些片操作设备在患者体内?

To take things to an extreme, would it ever be acceptable for a surgeon to leave some piece of operating equipment inside a patient?

虽然有可能会出现一种情况,其中除去那件装备的成本/风险超过把它留在成本/风险,并有可能在某些地方它是无害的,如果我看到这个问题张贴在SurgeonOverflow.com,看到比不,这将严重破坏了我的信心在医疗界。

Although it is possible that a circumstance could arise where the cost/risk of removing that piece of equipment exceeds the cost/risk of leaving it in, and there could be circumstances where it was harmless, if I saw this question posted on SurgeonOverflow.com and saw any answer other than "no," it would seriously undermine my confidence in the medical profession.

-

如果第三方库强迫我这种情况,将导致我严重怀疑有问题的图书馆的整体素质。这将是,如果我试驾了一辆汽车,发现一对夫妇松垫圈和螺母的杯架之一 - 它可能不是本身就是一个大问题,但它描绘缺乏对质量的承诺,所以我会考虑替代方案。

If a third party library forced this situation on me, it would lead me to seriously suspect the overall quality of the library in question. It would be as if I test drove a car and found a couple loose washers and nuts in one of the cupholders – it may not be a big deal in itself, but it portrays a lack of commitment to quality, so I would consider alternatives.

这篇关于是内存泄漏以往任何时候都好吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 23:45