Reference
Move ownership instead of copying bytes. Companion to lesson 3. MDN: Transferable objects.
// Same realm — explicit clone + optional move
const copy = structuredClone(u8, { transfer: [u8.buffer] });
// Other realm — implicit clone + optional move
worker.postMessage(u8, [u8.buffer]);
.buffer in the list.
byteLength === 0). A detached buffer cannot be cloned
or transferred again.
| Hard problem | Default |
|---|---|
| Large binary; sender is done with the bytes | Transfer |
| Both sides still need the bytes | Clone (or copy first, then transfer one copy) |
| Same-realm snapshot that must freeze the original |
structuredClone(value, { transfer }) — source
detaches
|
| BroadcastChannel / IndexedDB / History | Clone only — no transfer list |
| Small objects, Dates, Maps, DTOs | Clone; transfer is the wrong tool |
ArrayBuffer, MessagePort,
ImageBitmap, OffscreenCanvas,
ReadableStream / WritableStream /
TransformStream, VideoFrame,
AudioData. Marked [Transferable] in Web IDL.
Do not memorize the long tail — check MDN when a type is unfamiliar.