16.1 Weak Boxes

► |  | The Racket Reference

1 | Language Model
2 | Notation for Documentation
3 | Syntactic Forms
4 | Datatypes
5 | Structures
6 | Classes and Objects
7 | Units
8 | Contracts
9 | Pattern Matching
10 | Control Flow
11 | Concurrency and Parallelism
12 | Macros
13 | Input and Output
14 | Reflection and Security
15 | Operating System
16 | Memory Management
17 | Unsafe Operations
18 | Running Racket
| Bibliography
| Index

▼ | 16 | Memory Management

16.1 | Weak Boxes
16.2 | Ephemerons
16.3 | Wills and Executors
16.4 | Garbage Collection
16.5 | Phantom Byte Strings

On this page:

make-weak-box
weak-box-value
weak-box?

top ← prev up next →

#### 16.1`` Weak Boxes

A weak box is similar to a normal box (see Boxes), but when the garbage collector (see Garbage Collection) can prove that the content value of a weak box is only reachable via weak references, the content of the weak box is replaced with #f. A weak reference is a reference through a weak box, through a key reference in a weak hash table (see Hash Tables), through a value in an ephemeron where the value can be replaced by #f (see Ephemerons), or through a custodian (see Custodians).

> procedure (make-weak-box v) → weak-box?
> v : any/c

Returns a new weak box that initially contains v.

> procedure (weak-box-value weak-box [gced-v]) → any/c
> weak-box : weak-box?
> gced-v : any/c = #f

Returns the value contained in weak-box. If the garbage collector has proven that the previous content value of weak-box was reachable only through a weak reference, then gced-v (which defaults to #f) is returned.

> procedure (weak-box? v) → boolean?
> v : any/c

Returns #t if v is a weak box, #f otherwise.
top ← prev up next →