在VS C ++ 6.0中,哪些调试工具可以很好地发现内存泄漏的地方?
问题描述:
我的程序最终消耗掉了所有的内存并崩溃了...浏览代码,我找不到任何能做到这一点的东西.
My program eventually consumes all ram and crashes... looking through the code, I can't find anything that stands out that would do this.
答
是否可以修改代码以使用malloc
和free
的调试版本?如果是,请检查 _malloc_dbg 和
Could you modify the code to use the debug version of malloc
and free
? If yes, check _malloc_dbg and _free_dbg.
(您可以根据这些函数编写自己的new
和delete
运算符.)
(You could write own new
and delete
operators based on these functions.)
我记得VS 6.0没有_realloc_dbg
.
As I remember VS 6.0 has no _realloc_dbg
.
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC 1
#include <Crtdbg.h>
#define malloc(size) _malloc_dbg(size,_CLIENT_BLOCK,__FILE__,__LINE__)
#define free(addr) _free_dbg(addr,_CLIENT_BLOCK)
#endif