Please let me know, how to detect if the application has memory leak in linux platform. Which command/tool and what counters to track ?
Printable View
Please let me know, how to detect if the application has memory leak in linux platform. Which command/tool and what counters to track ?
Run the program (compiled with debug symbols) through valgrind. It will report any questionable memory-related actions, including leaks.
Thanks for you suggestion. Before doing that, is there any reliable linux utility, by which i can confirm if there application really leaks memory ?
Valgrind is the solution to that too. Valgrind is God for linux development.
Lindley: agreed, it often even helps me find the cause of segfaults faster than gdb...
htonivi: You may have to compile your code with debug symbols using -g to get backtraces (more detail). This might not be required though (it is when using gdb).
Then:
Note that your code will run way slower under Valgrind, of course, since it's doing a lot of run-time checking. If some of the backtraces are "optimized out" as you see with gdb, compile without optimizations (-O0).Code:gcc -g -o yourprog yourprog.c
valgrind --tool=memcheck --leak-check=full ./yourprog