如何检测内存泄漏 [英] how detect memory leaks

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

问题描述

如何检测内存泄漏CRT和MFC库链接?

how do i detect memory leaks When the CRT and MFC libraries are linked?

推荐答案

解决方案3应该是您的第一站(使用内置调试方法) )...



以下是关于如何直接从源代码使用它的信息(MSDN):

http://msdn.microsoft.com/en-us/library/7sx52ww7.aspx [ ^ ]
Solution 3 should be your first stop (using the built-in debugging methods)...

Here's the information on how to use it straight from the source (MSDN):
http://msdn.microsoft.com/en-us/library/7sx52ww7.aspx[^]


查找内存泄漏很困难。问题的基本性质是如何判断进程是否已经分配了一块内存。这是C#和Java中内存管理器的神奇之处(它分别具有IL和Javabyte代码的优点)。垃圾收集器确定变量是否超出范围并释放/释放该内存。有很多工具可以帮助您从代码中确定。以下是其中一个链接:



http:// deleaker .com /



如果没有源代码,就很难分析。我希望这会有所帮助。
Finding memory leaks is difficult. The basic nature of the problem is that how can you tell if the process is done with a piece of memory that has been allocated. This is the magic of memory managers in C# and Java (which have the benefit of IL and Javabyte code respectively). The garbage collector makes a determination about whether a variable has gone out of scope and deallocates/frees that memory. There are a lot of tools to help you determine that from your code. Here is a link to one of them:

http://deleaker.com/

Without the source code, it would be difficult to analyze. I hope this helps.


MFC已经包含内存泄漏检测机制。 Visual Studio在您的代码中生成几个标题行,在DEBUG中替换为 new 运算符,并调用 debug-new function,记录每个内存分配及其来源。在运行结束时,当 new 所做的所有分配都应该通过相应的删除 ,MFC在所有那些仍然打开的分配的输出窗口中输出一个列表。



这不是最复杂的内存泄漏跟踪器,但它在很多情况。只是学会解释这个列表,你会有很长的路要走。
MFC already contains a memory leak detection mechanism. Visual studio generates a couple of header lines in your code that replace in DEBUG builds the calls to the new operator with a call to a debug-new function, which records every single memory allocation and the place it comes from. At the end of the run, when all allocations made by new should have been given back by a corresponding call to delete, MFC outputs a list in the output window of all those allocations that are still open.

This is not the most sophisticated memory leak tracker, but it works quite well in many situations. Just learn to interpret that list and you get quite a long way.


这篇关于如何检测内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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