Re: GC with finalisation?

From: John Skaller (
Date: Fri Aug 27 1999 - 07:10:06 MET DST

Message-Id: <>
Date: Fri, 27 Aug 1999 15:10:06 +1000
To: Markus Mottl <>
From: John Skaller <>
Subject: Re: GC with finalisation?
In-Reply-To: <>

At 22:09 26/08/99 +0100, Markus Mottl wrote:
>> I seem to have several choices.
>> 1) implement reference counting for finalisation

>The main problem with reference counting is speed.

        I was hoping to avoid it ..

>It is possible to
>resolve circular references in linear time, but the constant overhead
>and the associated memory requirements are simply too large.

        I think this is less of a problem than actually
writing the collector, and then changing all my code
to use it.

>I would leave all the work to the OCaml-GC: use module "Weak" to register
>values (eg.: objects) to be finalized. Then check these arrays from
>time to time and call appropriate finalization functions for objects
>that have been reclaimed.

        That is an interesting idea -- but it won't work,
because the destructor must be called _before_ the object
is destroyed by the system. For example, one of my objects
maintains the table of contents for a document,
and when the object becomes unreachable, it is printed
to a file as HTML. Obviously, the object still has to exist
at this point, and retain all attributes.

        However, your idea of using weak arrays may
be useful after all, if I can create a 'symbol' for the
object, and put that into the weak array: the symbols
contains lists of symbols, representing objects the
object depends on. The collector will now collect
symbols, and by checking the weak array I can
execute destructors, and then release it
for collection (by removing it from a corresponding
'strong' array).

        The problem is: it will be slower than
reference counting, and not be entirely synchronous.
The advantage is it will finalise unreachable
objects with circular references. Also,
reference counting can be added anyhow,
to make non-circular finalisation synchronous.

        Hmm. Comments?

John Skaller email:
                phone: 61-2-96600850
                snail: 10/1 Toxteth Rd, Glebe NSW 2037, Australia

This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:24 MET