Commit | Line | Data |
---|---|---|
7f918cf1 CE |
1 | MLtonWeak |
2 | ========= | |
3 | ||
4 | [source,sml] | |
5 | ---- | |
6 | signature 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 | ||
15 | A weak pointer is a pointer to an object that is nulled if the object | |
16 | becomes <:Reachability:unreachable> due to garbage collection. The | |
17 | weak pointer does not itself cause the object it points to be retained | |
18 | by the garbage collector -- only other strong pointers can do that. | |
19 | For objects that are not allocated in the heap, like integers, a weak | |
20 | pointer will always be nulled. So, if `w: int Weak.t`, then | |
21 | `Weak.get w = NONE`. | |
22 | ||
23 | * `type 'a t` | |
24 | + | |
25 | the type of weak pointers to objects of type `'a` | |
26 | ||
27 | * `get w` | |
28 | + | |
29 | returns `NONE` if the object pointed to by `w` no longer exists. | |
30 | Otherwise, returns `SOME` of the object pointed to by `w`. | |
31 | ||
32 | * `new x` | |
33 | + | |
34 | returns a weak pointer to `x`. |