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
exception safety / RAII ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-03-08 (22:54)
From: Daniel Yokomizo <daniel_yokomiso@y...>
Subject: Re: Re: exception safety / RAII ?

"Jon Harrop" <> escreveu na mensagem
> On Monday 07 March 2005 18:47, Michael Walter wrote:


> > I have no idea about with finalizers in O'Caml (hence my more
> > broad/general statement), but in other languages I've worked with
> > there are several limitations which all basically origin in the fact
> > that finalization order in these languages was non-deterministic.
> Ok, I have found that, with a little thought and careful design
> this is not a problem in OCaml. In the case of DAG dependency graphs, my
> solution is to represent the dependency graph for the GC by maintaining a
> list of references to dependees in each object. This forces the GC to
> dependencies when collecting.

AFAIK it doesn't force the GC to respect the dependencies. A object is
garbage if it can't be reached from any root references, it doesn't matter
if other garbage objects still reference it. So if we have:

ROOT -> A -> B -> C

D -> E -> F

G -> B

H -> C

the GC can collect any of [D, E, F, G, H], in any order it wants, because
they're all garbage. An incremental collector could collect first [F, G, H]
because they are (say) large objects, and don't recycle the memory for [D,
E] until the next collection.

IIUC the current OCaml GC implementation may exhibit such properties (i.e.
respect dependencies) but it isn't required to do so.

> If the dependency graph is allowed to contain cycles then this might not
> I'm not sure though.
> -- 
> Dr Jon D Harrop, Flying Frog Consultancy Ltd.
> Objective CAML for Scientists