定位C++内存泄露位置
来源:互联网 发布:js里获取el表达式 编辑:程序博客网 时间:2024/06/14 02:29
vs2010
第一步:
#include <stdlib.h>
#include <crtdbg.h>int main()
{
#ifdef _DEBUG
//_crtBreakAlloc = 0;
#endif
char *malloc_s = (char*)malloc(1);
for (int i = 0; i < 10; i++)
{
free(malloc_s);
malloc_s = (char*)malloc(1);
}
_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
return 0;
}
在debug下运行(F5)上面代码,
OUTPUT中
hello1.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Cannot find or open the PDB file
'hello1.exe': Loaded 'C:\Windows\System32\msvcr100d.dll', Symbols loaded.
Detected memory leaks!
Dumping objects ->
{97} normal block at 0x004E5898, 1 bytes long.
Data: < > CD
Object dump complete.
The program '[1068] hello1.exe: Native' has exited with code 0 (0x0).
97 即为 内存泄露地址
第二步:
#include <stdlib.h>
#include <crtdbg.h>int main()
{
#ifdef _DEBUG
_crtBreakAlloc = 97;
#endif
char *malloc_s = (char*)malloc(1);
for (int i = 0; i < 10; i++)
{
free(malloc_s);
malloc_s = (char*)malloc(1);
}
_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
return 0;
}
在debug下运行(F5)上面代码,在 call stack中
hello1.exe!wmain(int argc, wchar_t * * argv) Line 17 + 0xa bytesC++
回车
定位到内存泄露位置即第几个循环。
在vs2011中
第一步
在主函数返回处加个断点
#include "stdafx.h"
#include <stdlib.h>
#include <crtdbg.h>
int main()
{
#ifdef _DEBUG
//_crtBreakAlloc = 64;
#endif
char *malloc_s = (char*)malloc(1);
for (int i = 0; i < 10; i++)
{
free(malloc_s);
malloc_s = (char*)malloc(1);
//a
}
_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
return 0;
}
在debug下(F5)运行
在 immediate window中查看
{64} normal block at 0x002C6718, 1 bytes long.
Data: < > CD
Object dump complete.
Detected memory leaks!
Dumping objects ->
{64} normal block at 0x002D6718, 1 bytes long.
Data: < > CD
Object dump complete.
64即为内存泄露地址处
第二部
#include "stdafx.h"
#include <stdlib.h>
#include <crtdbg.h>
int main()
{
#ifdef _DEBUG
_crtBreakAlloc = 64;
#endif
char *malloc_s = (char*)malloc(1);
for (int i = 0; i < 10; i++)
{
free(malloc_s);
malloc_s = (char*)malloc(1);
//a
}
_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
return 0;
}
在debug下运行(F5)
在call stack (调试--窗口--call stack)中
> Hello.exe!main() Line 19C++
回车
定位到内存泄露位置及第几行泄露
- 定位C++内存泄露位置
- FastMM 定位内存泄露的代码位置
- 定位程序内存泄露的位置
- android 快速定位内存泄露位置技巧
- FastMM 定位内存泄露的代码位置
- VS 查看是否有内存泄露的方法 定位位置
- VC++内存泄露定位
- 内存泄露定位
- VC内存泄露定位
- WinDbg定位内存泄露
- windbg定位内存泄露
- VC++内存泄露定位
- WinDbg定位内存泄露
- 内存泄露定位
- 内存泄露定位
- 内存泄露位置检测
- 定位内存泄漏位置
- BREW程序内存泄露定位
- java中的post请求之raw请求--微信api调用java代码示例
- strlen与sizeof计算char* 与char数组
- 指针和数组
- 获取某个view 的 截图的方法
- Win 8.1 Pro 安装 MSServer 2008 R2 企业版 失败 !
- 定位C++内存泄露位置
- S5PV210 三个Camera Interface/CAMIF/FIMC的区别
- UI框架: Bootstrap & Kickstart
- centos 7 安装 pgadmin3
- css 图片 文字居中对齐
- UI03事件处理
- 怎样从Eclipse当中打开一个存在的项目?
- Java子类对象中必有一个父类对象2
- 自己学驱动3——ARM-THUMB子程序调用规则ATPCS