← → or space · progress saves for Continue on the roadmap
Goal
Understand why you cannot pass a mutable object by reference to another isolate.
No shared heap
- Each isolate has its own allocator. A
ListorMapin isolate A is not visible to isolate B unless you send a copy or use special transfer rules.
What you can send
- Messages are usually copies of immutable-friendly data: numbers, bools,
null, strings, lists and maps of sendable values,SendPort, andTransferableTypedDatafor byte buffers (advanced).
Ports
ReceivePortlistens for messages.SendPorttargets a specific receive port. You pass aSendPortto the worker so it can reply.
Good habit
- Keep messages small and plain. Huge structures cost copy time; sometimes chunking or files + paths is better.
Practice tasks
- Try to send a
void Function()closure through aSendPortin a toy example and read the error or documentation explaining why it fails. - Contrast “copy message” overhead with “seconds of CPU” for a heavy parse; when is copying cheap enough?