CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2009
    Posts
    18

    Post Memory leak detection in linux applications

    Please let me know, how to detect if the application has memory leak in linux platform. Which command/tool and what counters to track ?

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Memory leak detection in linux applications

    Run the program (compiled with debug symbols) through valgrind. It will report any questionable memory-related actions, including leaks.

  3. #3
    Join Date
    Mar 2009
    Posts
    18

    Re: Memory leak detection in linux applications

    Thanks for you suggestion. Before doing that, is there any reliable linux utility, by which i can confirm if there application really leaks memory ?

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Memory leak detection in linux applications

    Valgrind is the solution to that too. Valgrind is God for linux development.

  5. #5
    Join Date
    Mar 2009
    Posts
    7

    Re: Memory leak detection in linux applications

    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:
    Code:
    gcc -g -o yourprog yourprog.c
    valgrind --tool=memcheck --leak-check=full ./yourprog
    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).
    Last edited by lanctot; March 14th, 2009 at 01:53 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured