[MLton] regions

Matthew Fluet fluet@cs.cornell.edu
Fri, 1 Oct 2004 19:39:50 -0400 (EDT)


> BTW does Mlton support weak references? It's been a while since I looked,
> but I don't remember seeing anything like weak references last I hacked on
> the MLton GC. :)

http://www.mlton.org/doc/user-guide/MLton_extensions.html#toc46

A weak pointer is a pointer to an object that is nulled if the object
becomes unreachable due to garbage collection. The weak pointer does not
itself cause the object it points to be retained by the garbage collector
-- only other strong pointers can do that. For objects that are not
allocated in the heap, like integers, a weak pointer will always be
nulled. So, if w: int Weak.t then Weak.get w = NONE.

signature MLTON_WEAK =
   sig
      type 'a t

      val get: 'a t -> 'a option
      val new: 'a -> 'a t
   end


In fact, MLton.Finalizable is built on top of MLton.Weak.