Detecting memory leaks

J

Jive

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
 
B

bowman

Jive said:
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.
 
E

Eddie Parker

Jive wrote:

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-
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,836
Latest member
BuyBlissBitesCBD

Latest Threads

Top