We can use “valgrind”, simply compile your code with -g option, and then run
valgrind --leak-check=full ./program > output.log
if you run “top” then you will see a process called “memcheck”.
this is a kind of output you will get:
==1651== Memcheck, a memory error detector.
==1651== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==1651== Using LibVEX rev 1804, a library for dynamic binary translation.
==1651== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==1651== Using valgrind-3.3.0-Debian, a dynamic binary instrumentation framework.
==1651== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==1651== For more details, rerun with: -v
==1651==
==1651==
==1651== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 33 from 1)
==1651== malloc/free: in use at exit: 0 bytes in 0 blocks.
==1651== malloc/free: 567 allocs, 567 frees, 147,342,292 bytes allocated.
==1651== For counts of detected errors, rerun with: -v
==1651== All heap blocks were freed -- no leaks are possible.
Filed under: Uncategorized | Tagged: c++, linux