Detecting memory leaks
eddie at kickingdragon.com
Sun Nov 21 20:30:19 CET 2004
>>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:
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!
More information about the Python-list