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: