Checking for memory leaks

This is a discussion on Checking for memory leaks within the C Programming forums, part of the General Programming Boards category; Is there a way to track a programs memory usage so I can make sure I don't have a memory ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    278

    Checking for memory leaks

    Is there a way to track a programs memory usage so I can make sure I don't have a memory leak issue?

    What I'm hoping for is some sort of function like mem_usage() or something that will return the amount of memory my program is using.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,662
    There are tools like Valgrind and Purify that can perform such memory leak detection.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,507
    If you're using Microsoft visual something-or-other, then read this
    http://msdn.microsoft.com/en-us/library/bebs9zyz.aspx
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    Quote Originally Posted by laserlight View Post
    There are tools like Valgrind and Purify that can perform such memory leak detection.
    Thanks, quiet helpful, how about C-Lint?
    Just GET it OFF out my mind!!

  5. #5
    Registered User
    Join Date
    Feb 2009
    Posts
    138
    lint only does static code analysis. if you use a library function where the source isn't available, lint can't tell you if the function allocated memory and you forgot free it. if it were that simple you could just write a macro wrapper around malloc and free to keep track of heap memory.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Meldreth View Post
    lint only does static code analysis. if you use a library function where the source isn't available, lint can't tell you if the function allocated memory and you forgot free it. if it were that simple you could just write a macro wrapper around malloc and free to keep track of heap memory.
    And I doubt that lint can follow code that allocates and frees memory in different functions - at least not well enough to know if it's ALWAYS freed or not.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  3. Problems about gcc installation
    By kevin_cat in forum Linux Programming
    Replies: 4
    Last Post: 08-09-2005, 09:05 AM
  4. checking for memory leaks
    By alpha in forum C++ Programming
    Replies: 2
    Last Post: 04-07-2003, 06:42 PM
  5. command in unix for checking memory leaks
    By sanju in forum Linux Programming
    Replies: 1
    Last Post: 01-22-2003, 05:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21