References:
Main: http://www.cnblogs.com/dhbzzz/archive/2009/06/04/1495973.html
Other: http://www.oschina.net/question/161952_24831
Http://msdn.microsoft.com/zh-cn/library/e5ewb1h3 (V = vs.80). aspx
Http://topic.csdn.net/u/20100530/19/3be8559f-824d-4d7e-8175-697992dfe7e0.html
There is valgrind on Linux. What tools does it have on windows ??
Method:
Stdafx. h:
# DEFINE _ crtdbg_map_alloc
# Include <stdlib. h>
# Include <crtdbg. h>
_ The definition of crtdbg_map_alloc must be added, so that you can clearly see which file line has a memory leak;
Add the following after # include of each CPP file in the project:
# Ifdef _ debug
# Define new debug_new
# Endif
Add
_ Crtsetdbgflag (_ crtdbg_alloc_mem_df | _ crtdbg_leak_check_df );
This statement automatically calls _ crtdumpmemoryleaks when the program exits.
Problems:
According to the "method", but the compilation shows: Error c2065: "debug_new": Undeclared identifier
Solution: add the include <afx. h> header file because debug_new is defined in the header file.
.
Result:
Output Window Display
Detected memory leaks!
Dumping objects->
E: \ lab \ task2-opt mshog \ mshogdlltest. cpp (15): {116} normal block at 0x003bf5f0, 40 bytes long.
Data: <> CD
Object dump complete.
2012-05-18
Xjs.xjtu@gmail.com