Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] GC and file descriptors
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-11-15 (15:56)
From: Ville-Pertti Keinonen <will@e...>
Subject: Re: [Caml-list] GC and file descriptors
On Sun, Nov 16, 2003 at 01:16:08AM +1100, skaller wrote:

> It is possible to modify the Ocaml collector to make finalisation
> orderly, but it is very expensive. It is also possible

Not just expensive, more like something you definitely don't want to
even try.  Python tries to have deterministic finalization, but
falls back on "normal" garbage collection for containers (with potential
cyclic references).  Perl doesn't even bother with that, instead it
doesn't resolve cyclic references at all.

Typically, the best you can do is explicit finalization; which can be
convenient using something similar to Lisp with-open-file constructs,
possibly with alternate interfaces and finalization on GC as a fallback
for poorly structured programs.

For more complicated cases with multiple references, what you probably
want is an explicit liveness count (separate from the GC/memory
references).  The liveness count can likewise be protected by something
similar to unwind-protect blocks.

Considering that OCaml doesn't have capturable continuations, things
are relatively simple.

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: