[ILUG] memory leaks...

From: kevin lyda (kevin at domain suberic.net)
Date: Tue 29 Feb 2000 - 22:29:33 GMT


i had a question here but i seem to have answered it, so i thought i'd
share...

memory leaks are really annoying. and they're also tough to spot.
glibc provides a method to spot them:

#include <mcheck.h>

and then call mtrace() at the start of main(). compile the program with
-g for debugging, and set the environment variable MALLOC_TRACE to a
file to log memory allocation and freeing. once you've run the program
run this:

mtrace <program> $MALLOC_TRACE

voila, it lists all the memory leaks and the lines where the memory was
allocated.

dunno if this works from c++, but then c++ programs are supposed to leak
like a sieve anyway so does it really matter?

kevin

-- 
kevin at domain suberic.net       "we were goin' for breakfast.  in canada.  we
fork()'ed on 37058400    made a deal: if she'd stop hookin', i'd stop
meatspace place: home    shootin' people.  maybe we were aiming high."
                                                   --porter, "payback"


This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:05:31 GMT