"Jon Harrop" <jon@jdh30.plus.com> escreveu na mensagem
news:200503080110.21839.jon@jdh30.plus.com...
> On Monday 07 March 2005 18:47, Michael Walter wrote:
[snip]
> > 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
beforehand,
> 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
respect
> 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
work.
> I'm not sure though.
>
> --
> Dr Jon D Harrop, Flying Frog Consultancy Ltd.
> Objective CAML for Scientists
> http://www.ffconsultancy.com/products/ocaml_for_scientists