Tool for detecting memory leaks [closed] Tool for detecting memory leaks [closed] unix unix

Tool for detecting memory leaks [closed]


Such tools usually instrument the exeutable with their own code. for instance they replace every call to malloc() and free() with their own functions which allows them to follow every allocation.

In Visual Studio this can be done automatically using just the C Runtime Library using functions from the family of _CrtDumpMemoryLeaks()


For basic leak detection you just need to hook into low level memory allocation routines, e.g. by patching malloc/free. You then track all allocations and subsequently report any that have not been freed at an appropriate point, e.g. just prior to exit.


For actual work, valgrind works quite well. It detects invalid read/write and memory leaks.

For hobby project, you can create your own memory management module which keeps track of various pointer allocation and its usage. If you don't see some mem location being used for long time, it might be a leak.