English 中文(简体)
视力演播室应用C++时发现的记忆泄露
原标题:Finding memory leaks in a C++ application with Visual Studio

在短链氯化石蜡中,我一直在利用阀门检查申请中是否有传闻。 视窗的对应物是什么? 能否通过2010年视频演播室来做到这一点?

问题回答

“2019年视觉演播室”有一个象样的记忆分析工具,可以在打字时通过互动使用,也可以通过节目制作(不打字),在以下两种情况下,我只举一个最低的例子。

主要想法是在这一过程的开始和结束时,对差距进行微调,然后对记忆状况进行比较,以发现潜在的记忆泄露。

Interactively

建立以下<代码>main.cpp文档(在新的专册中):

#include <string.h>
int main()
{
 int a = 1;
 char* s = new char[17];
 strcpy_s(s,17,"stackoverflow_pb");
 char* ss = new char[14];
 strcpy_s(ss, 14,"stackoverflow");
 delete[] ss;
 return 0;
}

然后:

  1. Put a breakpoint on the first line "int a..."
  2. Click Debug > Windows > Show Diagnostic Tools; and pick memory usage
  3. Then debug the code (F5), when the breakpoint is hit, click Take snapshot on the Memory Usage summary toolbar.
  4. Go to the last line "return 0.." (step over (F10) several times) and take another snapshot.
  5. Click on the red arrow in the second snapshot (in memory usage tab)
  6. this will open a new "snapshot" tab that permits you to compare this snapshot with the first one (or another one) and to detect memory leaks. In this example there is a memory leak for variable s (stackoverflow_pb). You can find it by double click the "char[]" object.

上述程序的关键步骤见以下图象:

“互动分析”/</a

By programming

将守则改为:

#include <iostream>

#include "windows.h"
#define _CRTDBG_MAP_ALLOC //to get more details
#include <stdlib.h>  
#include <crtdbg.h>   //for malloc and free
int main()
{
    _CrtMemState sOld;
    _CrtMemState sNew;
    _CrtMemState sDiff;
    _CrtMemCheckpoint(&sOld); //take a snapshot
    char* s = new char[17];
    strcpy_s(s, 17, "stackoverflow_pb");
    char* ss = new char[14];
    strcpy_s(ss, 14, "stackoverflow");
    delete[] ss;
    _CrtMemCheckpoint(&sNew); //take a snapshot 
    if (_CrtMemDifference(&sDiff, &sOld, &sNew)) // if there is a difference
    {
        OutputDebugString(L"-----------_CrtMemDumpStatistics ---------");
        _CrtMemDumpStatistics(&sDiff);
        OutputDebugString(L"-----------_CrtMemDumpAllObjectsSince ---------");
        _CrtMemDumpAllObjectsSince(&sOld);
        OutputDebugString(L"-----------_CrtDumpMemoryLeaks ---------");
        _CrtDumpMemoryLeaks();
    }
    return 0;
}

同样,但通过编码,你可以将其融入自动建筑系统,其职能是:_CrtMemCheckpoint<<<<>>> 参考书目/参考书目/目录 相比之下,血清和回归的真实记忆有所不同。

Since it is the case, it enters the conditional block and prints details about the leaks via several functions (see _CrtMemDumpStatistics , _CrtMemDumpAllObjectsSince and _CrtDumpMemoryLeaks - the latter doesn t require snapshots).

参看该产出,在最后一行“返回0”上打了一个断点,打上了,并看着 de。 产出如下:

“在座的影像描述”/


获取更多信息,见以下链接:

How about 视觉探测器? 它没有被削弱,但我认为它是最受欢迎的。

Dr. Memory是一种记忆监测工具,能够查明与记忆有关的方案错误,例如:获得未开端记忆的机会、获得不可弥补的记忆的机会(包括分配的蒸气单位之外、蒸气流和溢出)、获得免费记忆的机会、双重自由、记忆和(视窗)处理泄漏、全球空间数据基础设施使用差错以及获得未保留的地方存储器。

记忆博士在视窗、赖恩、Mac、或ARM硬件上运行未经修改的双版。

记忆博士以

Application Verifier是检测本地(C或C++)应用中泄漏的一个良好工具。 你可以与视觉演播室或WinDbg一起使用。 除了记忆泄露外,你还可以检查黑色的腐败,处理错误的做法。 与WinDbg(!analyze-v)一起使用用户提供了很好的见解。

你们可以利用DevPartner工具,利用视觉演播室,在C++应用中发现传闻。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签