Check for Memory leakage in Windows

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.