本文介绍了如何避免在C / C内存泄漏++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是一些技巧,我可以使用,以避免在我的应用程序的内存泄漏?在我目前的项目中,我使用一个工具INSURE ++,它找到了内存泄漏并生成报告。

What are some tips I can use to avoid memory leaks in my applications? In my current project I use a tool "INSURE++" which finds the memory leak and generate the report.

除了工具是没有任何识别内存泄漏和克服方法。

Apart from the tool is there any method to identify memory leaks and overcome it.

推荐答案

有这样做的三种主要方式。

There are three main ways of doing this.

首先是要的不会产生内存泄漏的摆在首位。防御性编程技术是非常宝贵的在这里。看到这个<一个href=\"https://www.securecoding.cert.org/confluence/download/attachments/40402999/04+Dynamic+Memory.pdf?version=1&modificationDate=1267372189000\">excellent presentation 对于这个问题的一个总结,或者安全Ç编码。我比较熟悉C比C ++,但据我所知,C ++的这里是有用的。

The first is to not create memory leaks in the first place. Defensive programming techniques are invaluable here. See this excellent presentation for a summary of this issues, or the relevant chapter in Secure C Coding. I am more familiar with C than C++, but I understand that C++'s smart pointers are useful here.

第二种方法的静态分析的,它试图在你的源 - code检测错误。这一类的原始工具的皮棉的,这是可悲的是,现在已经过时。最好的工具,因为据我所知,是商业,如。然而,一些free工具确实存在。

A second approach static analysis, which attempts to detect errors in your source-code. The original tool in this category is lint, which is now sadly outdated. The best tools, as far as I know, are commercial such as coverty. However, some free tools do exist.

第三种方法是在运行时检测内存泄漏,喜欢的 INSURE ++ 的一样。 是极好这里强烈推荐。它可以帮助你已经引入了抓虫子。如果你有一个具有良好code覆盖测试套件这是特别有帮助。

The third approach is to detect memory leaks at runtime, like INSURE++ does. Valgrind is excellent here and highly recommended. It may help catch bugs you've already introduced. It is especially helpful if you do have a test suite that has good code coverage.

这篇关于如何避免在C / C内存泄漏++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 12:52