Re: Weak pointers

From: Damien Doligez (Damien.Doligez@inria.fr)
Date: Fri Mar 21 1997 - 18:26:14 MET


Date: Fri, 21 Mar 1997 18:26:14 +0100
From: Damien Doligez <Damien.Doligez@inria.fr>
Message-Id: <199703211726.SAA05996@tobago.inria.fr>
To: caml-list@pauillac.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
point.

>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.

-- Damien



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:10 MET