[ILUG] memory leaks...

kevin lyda kevin at suberic.net
Tue Feb 29 22:29:33 GMT 2000


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




More information about the ILUG mailing list