My program eventually consumes all ram and crashes... looking through the code, I can't find anything that stands out that would do this.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Could you modify the code to use the debug version of malloc
and free
? If yes, check _malloc_dbg and _free_dbg.
(You could write own new
and delete
operators based on these functions.)
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
回答2:
You can try BoundsChecker (now DevPartner): http://www.microfocus.com/products/micro-focus-developer/devpartner/index.aspx
You will be able to see memory leaks, interface leaks and other problems in your code.
回答3:
Depending on the type of leak you can use umdh, or debugdiag as simple tools, otherwise I would recommend windbg. All of these are free and are part of debugging tools for windows, you can Google for tutorials on all these tools. The command for automatic leak finding in windbg is !heap -l.