Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / src / MLtonWeak.adoc
CommitLineData
7f918cf1
CE
1MLtonWeak
2=========
3
4[source,sml]
5----
6signature MLTON_WEAK =
7 sig
8 type 'a t
9
10 val get: 'a t -> 'a option
11 val new: 'a -> 'a t
12 end
13----
14
15A weak pointer is a pointer to an object that is nulled if the object
16becomes <:Reachability:unreachable> due to garbage collection. The
17weak pointer does not itself cause the object it points to be retained
18by the garbage collector -- only other strong pointers can do that.
19For objects that are not allocated in the heap, like integers, a weak
20pointer will always be nulled. So, if `w: int Weak.t`, then
21`Weak.get w = NONE`.
22
23* `type 'a t`
24+
25the type of weak pointers to objects of type `'a`
26
27* `get w`
28+
29returns `NONE` if the object pointed to by `w` no longer exists.
30Otherwise, returns `SOME` of the object pointed to by `w`.
31
32* `new x`
33+
34returns a weak pointer to `x`.