[Gc] Debugging: getting a list of objects in use dumped

Fergus Henderson fjh at cs.mu.oz.au
Thu Feb 19 15:49:04 PST 2004

On 19-Feb-2004, Alec Orr <Alec.Orr at wbemsolutions.com> wrote:
> 2.  You can use the garbage collector is a leak detector (which will 
> give the address of objects not cleaned since the last call to 
> GC_gcollect() ).

I don't think that is useful advice for the original poster's situation.
The leak detector option is intended for detecting leaks in applications
which explicitly deallocate all of their unused memory, so any memory
which is unreferenced but not explicitly deallocated will be considered
a leak.  But for applications in GC'd languages such as Java, the program
is NOT expected to explicitly deallocate memory, and memory leaks occur
when memory that will no longer be used remains referenced.

To find those kinds of leaks, you should use the functions defined in
gc_backptr.h, in particular GC_generate_random_backtrace().
Run your program until it has leaked a lot, i.e. until a substantial
fraction of the retained memory is memory which ought to have been collected.
Then call GC_generate_random_backtrace() -- perhaps from within gdb,
after setting a breakpoint at the appropriate point.
You may have to try this a few times until you get an object which
you think ought to have been collected.  Then you will be able to see
which chain of pointers caused it to be retained.

Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <https://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.

More information about the Gc mailing list