Re: GC with finalisation?

From: Markus Mottl (
Date: Thu Aug 26 1999 - 23:09:32 MET DST

From: Markus Mottl <>
Message-Id: <>
Subject: Re: GC with finalisation?
To: (John Skaller)
Date: Thu, 26 Aug 1999 22:09:32 +0100 (MET DST)
In-Reply-To: <> from "John Skaller" at Aug 24, 99 01:36:43 pm

> I seem to have several choices.
> 1) implement reference counting for finalisation
> * disadvantage: same problem as CPython: doesn't resolve
> circular references properly
> * disadvantage: overhead and coding complexity
> * advantage: synchronous finalisation

The main problem with reference counting is speed. It is possible to
resolve circular references in linear time, but the constant overhead
and the associated memory requirements are simply too large.

Anyway, there is a nice fortune cookie pointing out potential problems
with recursive datastructures when doing reference counting:

    One day a student came to Moon and said, "I understand how to make
  a better garbage collector. We must keep a reference count of the
  pointers to each cons."
    Moon patiently told the student the following story -- "One day a
  student came to Moon and said, "I understand how to make a better
  garbage collector..."

[snip GC approaches]

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.


Markus Mottl,,

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