I am searching for memory leak detection library.
Something like I would just include it into source code then it should start detecting. External programs might be good but i was looking for some library which can be linked into executable.
This i am searching for Windows.
You can use some techniques in your code to detect memory leak. The most common and most easy way to detect is, define a macro say, DEBUG_NEW and use it, along with predefined macros like __FILE__
and __LINE__
to locate the memory leak in your code. These predefined macros tell you the file and line number of memory leaks.
DEBUG_NEW is just a MACRO which is usually defined as:
#define DEBUG_NEW new(__FILE__, __LINE__)
#define new DEBUG_NEW
So that wherever you use new
, it also can keep track of the file and line number which could be used to locate memory leak in your program.
And __FILE__
, __LINE__
are predefined macros which evaluate to the filename and line number respectively where you use them!
Read the following article which explains the technique of using DEBUG_NEW with other interesting macros, very beautifully:
A Cross-Platform Memory Leak Detector
From Wikpedia,
Debug_new refers to a technique in C++ to overload and/or redefine operator new and operator delete in order to intercept the memory allocation and deallocation calls, and thus debug a program for memory usage. It often involves defining a macro named DEBUG_NEW, and makes new become something like new(_FILE_, _LINE_) to record the file/line information on allocation. Microsoft Visual C++ uses this technique in its Microsoft Foundation Classes. There are some ways to extend this method to avoid using macro redefinition while still able to display the file/line information on some platforms. There are many inherent limitations to this method. It applies only to C++, and cannot catch memory leaks by C functions like malloc. However, it can be very simple to use and also very fast, when compared to some more complete memory debugger solutions.
I can suggest Visual Leak Detector, it is much easier to use than the Visual Studio built-in one.
For me this was for very long time the best tool: http://www.paulnettle.com/pub/FluidStudios/MemoryManagers/Fluid_Studios_Memory_Manager.zip Just include 1 header file and you're done with it :)
Visual studio has such feature on Windows. See http://msdn.microsoft.com/en-us/library/e5ewb1h3(v=VS.90).aspx . Under linux I do not know if such things exist, but valgrind is really good to find all kind of memory problems (not only leaks, but also invalid reads for instance).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With