From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA04504 for caml-redistribution; Sat, 28 Aug 1999 19:20:32 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA29340 for ; Thu, 26 Aug 1999 22:09:39 +0200 (MET DST) Received: from miss.wu-wien.ac.at (miss.wu-wien.ac.at [137.208.107.17]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id WAA21753 for ; Thu, 26 Aug 1999 22:09:38 +0200 (MET DST) Received: (from mottl@localhost) by miss.wu-wien.ac.at (8.9.0/8.9.0) id WAA29246; Thu, 26 Aug 1999 22:09:32 +0200 (MET DST) From: Markus Mottl Message-Id: <199908262009.WAA29246@miss.wu-wien.ac.at> Subject: Re: GC with finalisation? To: skaller@maxtal.com.au (John Skaller) Date: Thu, 26 Aug 1999 22:09:32 +0100 (MET DST) Cc: caml-list@inria.fr (OCAML) In-Reply-To: <3.0.6.32.19990824133643.009a89a0@mail.triode.net.au> from "John Skaller" at Aug 24, 99 01:36:43 pm X-Mailer: ELM [version 2.4 PL21] MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: weis > 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. Regards, Markus -- Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl