[gclist] garbage collection of dynamically loaded objects

Fergus Henderson fjh@cs.mu.oz.au
Wed, 31 Jan 2001 20:02:01 +1100


Hi,

Has anyone tried garbage collecting dynamically loaded objects that
were loaded with dlopen()?

A student here who is working on a SOAP interface for Mercury,
Ina Cheng, has been using Mercury's dynamic loading support.
But she ran into a problem where her code was calling dl__close,
which is the Mercury interface to dlclose(), while there were still
live references to static data defined in the dynamically loaded
module.  Part of the problem was that we hadn't documented the dangers
of dl__close.  But figuring out when you have references to static
data in the dynamically loaded module is tricky, and may require some
understanding of implementation details of the Mercury implementation.
In an ideal world, you wouldn't need to call dl__close at all,
because the system would garbage collect the dynamically loaded
module when it was no longer referenced.

The Boehm (et al) conservative collector, which we're using, has code
to trace references *from* (writable) static data in dynamically loaded
modules.  But it doesn't have any code to trace references *to*
code or static data in dynamically loaded modules.  Has anyone
considered doing that?

P.S. I guess it only makes sense to garbage collect objects that were
loaded without the RTLD_GLOBAL option, because if that option is enabled,
the object file might be used to resolve references in other dynamically
loaded objects, so the garbage collector can never determine when it
is safe to collect it.

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