Date: Fri, 21 Mar 1997 18:26:14 +0100
From: Damien Doligez <Damien.Doligez@inria.fr>
Subject: Re: Weak pointers
>I wonder when Weaks pointers are erased by the GC.
With the incremental garbage collector, it's hard to say.
At the soonest, at the end of the first marking phase that ends after
all (strong) pointers to the object have disappeared; at the latest at
the end of the next marking phase, unless you have created more strong
pointers in the meantime by using Weak.get on the weak pointer.
In any case, integers and constant constructors (which are represented
by integers) are never erased by the GC (there is no memory to be
gained by erasing them). But there's of course no guarantee on this
>As soon as it can be or when there is no more memory ?
The answer is: as soon as it can be, for some meaning of "can".
Caml is not SML/NJ. You don't need to assume that it will use all
your memory, and then some.
>Is it a good idea to use weak pointers to implement more
>or less a cache ?
If the objects are only in your cache (and not also in some other data
structure used by your program), no because the GC will erase them as
soon as it can.
This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:10 MET