Detecting memory leaks

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jive

    #1

    Detecting memory leaks

    The short form of the question is, how can I trace memory usage (preferably
    from C) with an eye toward finding out if I'm leaking memory?

    I would have thought there would be a ton of info on this, but I've been
    googling for half and hour and I keep coming up empty.

    I've recently ported Python to a realtime operating system, and I've
    implemented a small C extension module. The system controls a piece of
    equipment. A test program runs for about a week and then crashes. The
    first thing I think of to eliminate is the possibility of a memory leak.

    I would also welcome a list of common causes of infant mortality in new
    ports and extensions.

    jdadson at yahoo dott com


  • bowman

    #2
    Re: Detecting memory leaks

    Jive wrote:
    [color=blue]
    > The short form of the question is, how can I trace memory usage
    > (preferably from C) with an eye toward finding out if I'm leaking memory?[/color]

    Have you looked at efence or dmalloc? I don't know if either could be ported
    to your RTOS. efence depends on the hardware and both make assumptions on
    the memory allocation schemes.

    Comment

    • Eddie Parker

      #3
      Re: Detecting memory leaks

      [color=blue]
      >Jive wrote:
      >
      >
      >[color=green]
      >>The short form of the question is, how can I trace memory usage
      >>(preferably from C) with an eye toward finding out if I'm leaking memory?
      >>
      >>[/color][/color]

      If you're interested in a 'poor-mans' solution, or rather a
      "not-built-here" solution, you could do something like the following:

      (in debug)

      1) Override all new and deletes
      2) Have new add to a linked list, placing __FILE__, __LINE__ and a
      pointer to the memory created
      3) Have delete remove from said linked list
      4) Have another call that displays the linked list's contents out.

      Then, simply have the call that displays the linked lists contents
      execute whenever you believe you should have all the objects deleted.

      I realize this could fail for a variety of reasons:
      a) Some(/all?) parts of your code don't use new and delete
      b) You want to detect memory leaks in an environment where you still
      have *some* items newed
      c) I missed the point completely and gave poor advice. :)

      Anyways, I'm not sure if this will help, but it's what I use in my apps.
      Apologies if it doesn't!

      -e-

      Comment

      Working...