内存泄露跟踪

原程序

#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
就出现在库中

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值