C ++ Memory leakage check

Source: Internet
Author: User

1. How does vs2008 check for Memory leakage?

2. How to check C ++ in LinuxProgramMemory leakage?

1. How does vs2008 check for Memory leakage?

In vs2008, it is relatively simple to check for Memory leakage. Create a new win32console application that contains the following header files:

# DEFINE _ crtdbg_map_alloc

# Include <stdlib. h>

# Include <crtdbg. h>

 

 

PassInclude# Include <crtdbg. h>: maps malloc and free to _ malloc_dbg and _ free_dbg. These two functions track the memory application and release. Test the following program:

# DEFINE _ crtdbg_map_alloc # include <stdlib. h> # include <crtdbg. h> # include <iostream> int main (){ Int * PTR = new int (); _ Crtdumpmemoryleaks (); Return 0;

}

 

 

Make sure that in debug (relative to release) mode, F5, you can view the int size memory applied above in the output window, but the memory leakage error is not released.

More details: http://msdn.microsoft.com/en-us/library/x98tx3cf (V = vs.80). aspx

2. in Linux, how does one check program memory leakage?

Download valgrind 2.1

 

2.2 decompress

2.3 start compiling valgrind

 

Then start make and make install to complete the compilation.

2.4 Test.

A simple program with Memory leakage:

# Include <iostream> int main () {using namespace STD; int * P = new int (); Return 0 ;}

Compile the above program and use valgrind to detect memory leaks as follows:

 

 

 

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.