► |  | Reference: Racket

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

▼ | 15 | Memory Management

15.1 | Weak Boxes
15.2 | Ephemerons
15.3 | Wills and Executors
15.4 | Garbage Collection

On this page:

make-ephemeron
ephemeron-value
ephemeron?

top ← prev up next →

#### 15.2`` Ephemerons

An ephemeron is similar to a weak box (see Weak Boxes), except that

- an ephemeron contains a key and a value; the value can be extracted from the ephemeron, but the value is replaced by #f when the automatic memory manager can prove that either the ephemeron or the key is reachable only through weak references (see Weak Boxes); and

- nothing reachable from the value in an ephemeron counts toward the reachability of an ephemeron key (whether for the same ephemeron or another), unless the same value is reachable through a non-weak reference, or unless the value’s ephemeron key is reachable through a non-weak reference (see Weak Boxes for information on weak references).

In particular, an ephemeron can be combined with a weak hash table (see Hash Tables) to produce a mapping where the memory manager can reclaim key–value pairs even when the value refers to the key.

( make-ephemeron key v) → ephemeron?
key : any/c
v : any/c

Returns a new ephemeron whose key is key and whose value is initially v.

( ephemeron-value ephemeron) → any
ephemeron : ephemeron?

Returns the value contained in ephemeron. If the garbage collector has proven that the key for ephemeron is only weakly reachable, then the result is #f.

( ephemeron? v) → boolean?
v : any/c

Returns #t if v is an ephemeron, #f otherwise.
top ← prev up next →