原程序
#include "stdlib.h"
#include <crtdbg.h>
#include "stdio.h"
#include "string"
int main()
{
int i = 10;
while (i--)
{
char * pChar = new char[1024];
strcpy(pChar, "5ds133333333333333sdf3sd1fs13f51sdf51s6df51s6d");
}
return 0;
}
存在内存泄露,但是不显示。
#define _CRTDBG_MAP_ALLOC
#include "stdafx.h"
#include "stdlib.h"
#include <crtdbg.h>
#include "stdio.h"
#include "string"
inline void EnableMemLeakCheck()
{
_CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
}
int main()
{
_CrtDumpMemoryLeaks();
EnableMemLeakCheck();
int i = 10;
while (i--)
{
char * pChar = new char[1024];
strcpy(pChar, "5ds133333333333333sdf3sd1fs13f51sdf51s6df51s6d");
}
return 0;
}
显示内存泄露信息 但是不打印内存泄露信息
#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
显示内存泄露在程序中的文件名和所在的行数
如果添加此定义,但是注释掉#define _CRTDBG_MAP_ALLOC
就出现在库中