Memory leak finder
来源:互联网 发布:购物网站数据库问题 编辑:程序博客网 时间:2024/05/08 07:00
- Download source files - 10.51 KB
- Download DLL files - 19.08 KB
Introduction
Have you ever had a memory leak? Wished you knew where you allocated it and how? Is your boss cheap and refuses to buy Boundchecker or another debugging tool?
Here is the solution for you. A memory leak detector compiled directly into your code. It reports memory leaks with call stack of the allocation down to a user defined depth.
As an add-on, it does simple checks of the memory before and after the memory block, to track buffer overwrites.
Usage
Include tracealloc.cpp in your project. Define DETECT_LEAKS
in the project settings. Compile. Run your application. Memory leaks are reported into your debug output window when the application terminates. Just click the memory leak and the correct file and line will be shown.
You can find further instructions in the source code.
How is it done?
The code overrides operator new
and operator delete
. For each allocation made, the code allocates extra space for tracking, call stack and no-mans-land. The current call stack is fetched and remembered, finally the code puts the newly allocated block in a linked list and the requested memory is returned.
When a memory block is deleted, the header is found and checked for buffer overwrites. The memory block is then removed from the linked list and deallocated.
When the program terminates, the global memory tracker object is deleted. The destructor traverses the linked list for memory blocks that isn’t deleted (= leaked memory). It then fetches symbol information for the call stacks and dumps the information in the debug console.
Limitations
The code is Microsoft Visual Studio and Win32 specific. It requires a debug build. The code is C++ specific. It handles new
/delete
but not malloc
/free
. The code will run slower with leak detection active (roughly at half normal debug build speed).
Finally
I want to thank Zoltan Csizmadia who wrote ExtendedTrace
. I have used parts of his code for stack walking and symbol lookups.
I also want to thank the Code Project community. I have found many solutions or pointers in the right direction here. I hope I have given something back with this contribution.
Thank you!
License
This article, along with any associated source code and files, is licensed under The MIT License
- Memory leak finder
- C++ Memory Leak Finder
- C++ Memory Leak Finder
- C++ Memory Leak Finder(转)
- C++ Memory Leak Finder C++内存泄露检测器
- Memory Leak
- memory leak
- Memory leak
- 谷歌开源JavaScript内存泄露检测工具 Leak Finder
- detect memory leak macro
- detect memory leak macro
- Enabling Memory Leak Detection
- memory leak( 纯属备份)
- Pixbuf causes memory leak
- solaris memory leak
- Memory Leak分析分享
- memory leak in occi
- Detecting Memory Leak
- 写书评,得《观止》,程序员自我修炼
- 图像术语知识
- 视频编码之YCbCr、YUV
- dbgrideh快速导出excel
- [CSS]详解display:inline | block |inline-block的区别
- Memory leak finder
- 超级实用且不花哨的js代码大全
- gfdg
- 从tomcat6的页面上管理你从Myeclipse部署到tomcat的项目
- wsdl2java使用
- HMM学习最佳范例五:前向算法2
- TempDB 优化
- 转贴:c指针详解
- ubuntu耳机没有声音