English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Re: GC with finalisation?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1999-08-28 (17:20)
From: Markus Mottl <mottl@m...>
Subject: Re: GC with finalisation?
> 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, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl