#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _DEBUG
#define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
#else
#define DEBUG_CLIENTBLOCK
#endif // _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#ifdef _DEBUG
#define new DEBUG_CLIENTBLOCK
#endif // _DEBUG
int main()
{
int *a = NULL;
a = (int *)malloc(100*sizeof(int));
printf("hello");
/**
写在 运行结果前 :
在 不启用 free() 函数前, 不 添加任何断点, 启用F5进行debug调试模式,
在vs2013 编辑器的调式/输出中可以看到如下结果.
Detected memory leaks!
Dumping objects ->
d:\documents\visual studio 2012\projects\mem_leaks\main.cpp(22) : {66} normal block at 0x003A9D38, 400 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.
说明有内存泄漏了,
**/
//free(a);
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF);
return 0;
}
C vs2013 内存泄漏排查
猜你喜欢
转载自my.oschina.net/u/1579560/blog/1815699
今日推荐
周排行