检验内存泄漏memwatch的使用

2019-07-12 22:48发布

项目中检索内存泄漏,memwatch的使用首先下载源码,可以在网上down一份源码,如果找不到可以在我的资源那下载,我已经上传。下载后将其加入到项目中,在c盘下新建一个文件夹命名为itcast。然后在属性/预编译处理加入宏  分别是MEMWATCH和MW_STDIO
写测试代码。#define _CRT_SECURE_NO_WARNINGS #include #include #include #include "memwatch.h" int getMem(char **myp) { char *p = NULL; p = (char *)malloc(100); strcpy(p, "aaaaabbbbb"); *myp = p; return 0; } void main() { char *myp = NULL; getMem(&myp); printf("%s ", myp); system("pause"); return; }然后进入c盘找到itcast文件夹,里面已经生成一个libmem.log文件。打开看看内容是这样的============= MEMWATCH 2.71 Copyright (C) 1992-1999 Johan Lindh ============= Started at Wed May 23 19:42:23 2018 Modes: 64-bit mwDWORD==(unsigned long) mwROUNDALLOC==8 sizeof(mwData)==32 mwDataSize==32 Compiled using Microsoft C 19.00 Stopped at Wed May 23 19:42:25 2018 unfreed: <1> d:文档visual studio 2015projects内存泄漏内存泄漏内存泄漏.c(10), 100 bytes at 03359900 {61 61 61 61 61 62 62 62 62 62 00 FE FE FE FE FE aaaaabbbbb......} Memory usage statistics (global): N)umber of allocations made: 1 L)argest memory usage : 100 T)otal of all alloc() calls: 100 U)nfreed bytes totals : 100项目中发生了内存泄漏已经被记录下来。