[m-dev.] track down a memory leak

Peter Ross peter.ross at miscrit.be
Wed Sep 13 02:06:34 AEDT 2000


On Fri, Sep 08, 2000 at 11:46:44AM +1100, Fergus Henderson wrote:
> On 07-Sep-2000, Peter Ross <peter.ross at miscrit.be> wrote:
> > Any advice on how to track down what memory is not being collected?
> > The compute example from my thread tutorial doesn't run in constant
> > memory and as far as I know it should.  I would like to see what
> > memory is not being collected and if possible why?
> 
> Compile the garbage collector with -DGC_DEBUG and -DKEEP_BACKPTR.
> Run the program under gdb.  Set a breakpoint at some suitable point,
> and when the breakpoint is reached, type `call GC_generate_random_backtrace'.
> This will pick a random piece of heap and print a backtrace which
> explains why that piece of memory is not being collectable by showing
> how it is reachable from one of the roots.
> 
> Do this a few times, and see which addresses keep cropping up.
> 
> See boehm_gc/backtrace.h for more info.
> 
> Unfortunately the backtrace is not particularly clear because it just
> prints hex addresses, not Mercury terms.  And regrettably that isn't easy
> to remedy.  However, if you look around at the memory with gdb's "p"
> or "p/a" commands you can often figure out what it is.
> If you know what Mercury type it is, you can print it out by calling
> ML_io_print_to_current_stream() from the debugger. E.g. if you happen
> to know that address 0x12345678 has type `int', you can print it using
> 
> 	gdb> call ML_io_print_to_current_stream(
> 		&mercury_data___type_ctor_info_int_0, 0x12345678);
> 

I have the unfortunate problem that the heap only grows running under
the grade hlc.par.gc under windows, I have finally got a DLL built with
GC_generate_random_backtrace() available.  However it prints out
nothing!

Any ideas what to do next?

Pete
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list