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] Is Weak.get guaranteed to return Some until finalisation is executed?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-11-18 (12:20)
From: Damien Doligez <damien.doligez@i...>
Subject: Re: [Caml-list] Is Weak.get guaranteed to return Some until finalisation is executed?
On Friday, November 14, 2003, at 11:07 PM, Aleksey Nogin wrote:

> Currently the documentation for the Weak module seems to imply that 
> the Weak.get can return None whenever it feels like it. Is there any 
> guarantees as to when things are required to stay in the weak array?

It is not documented, mostly because the documentation doesn't introduce
the notions needed to talk about sharing, pointers, and liveness of
data.  It would be nice to do it, in order to give some precise
specification of (==), weak pointers, and finalisation.  But it is
a large amount of work, as the corresponding theoretical work doesn't
exist (as far as I know), and we should carefully avoid over-specifying.

>  In particular, if I call GC.finalise on a heap-allocated value and 
> then stick a value into a weak array, can I be sure that Weak.get will 
> return   Some until after the finalisation function is executed (and 
> finishes its execution)?

Definitely not.  Weak pointers are erased first, and finalisation
functions are called afterward.  When the finalisation function is
called, it really has the only existing pointer to the value.

-- Damien

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