Detecting memory leaks

Discussion in 'Python' started by Jive, Nov 21, 2004.

  1. Jive

    Jive Guest

    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
    Jive, Nov 21, 2004
    #1
    1. Advertising

  2. Jive

    bowman Guest

    Jive wrote:

    > 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?


    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.
    bowman, Nov 21, 2004
    #2
    1. Advertising

  3. Jive

    Eddie Parker Guest


    >Jive wrote:
    >
    >
    >
    >>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?
    >>
    >>


    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-
    Eddie Parker, Nov 21, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ASP.Confused

    ASP.NET - Detecting memory leaks

    ASP.Confused, Jul 16, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,729
    Marina
    Jul 16, 2004
  2. Diego Martins
    Replies:
    4
    Views:
    313
    Diego Martins
    Oct 9, 2006
  3. Ilias Lazaridis

    Detecting memory leaks on apache, mod_python

    Ilias Lazaridis, Dec 17, 2007, in forum: Python
    Replies:
    14
    Views:
    572
    Ilias Lazaridis
    Dec 23, 2007
  4. Jerome Sui

    detecting memory leaks in Perl

    Jerome Sui, Jul 13, 2003, in forum: Perl Misc
    Replies:
    0
    Views:
    123
    Jerome Sui
    Jul 13, 2003
  5. Replies:
    5
    Views:
    992
Loading...

Share This Page