What are isolates in Dart and when do you need them?
Short Answer
An isolate is Dart's unit of concurrency — a separate memory heap and event loop running independently, with no shared mutable state — used to run CPU-heavy work in parallel without blocking the UI thread.
Dart's main isolate runs your UI and event loop; `await`ing a network call doesn't block it because I/O is non-blocking, but genuinely CPU-bound work (parsing a huge JSON file, image processing, heavy computation) does block it, causing dropped frames and jank, because there's no thread for it to yield to.
Isolates solve this by running that work on a separate isolate with its own memory — communication happens only via message-passing (ports), never shared memory, which is why Dart doesn't need locks/mutexes for isolate-to-isolate communication. The easy way to spin one up for a single task is `compute()` from Flutter, which runs a top-level function on a new isolate and returns its result as a Future. For longer-lived background work, you manage an `Isolate` and `ReceivePort` directly.
Code Example
// Runs on a separate isolate, doesn't block the UI thread
final result = await compute(parseHeavyJson, rawJsonString);
List<Item> parseHeavyJson(String raw) {
final data = jsonDecode(raw) as List;
return data.map((e) => Item.fromJson(e)).toList();
}Common Mistakes
- ×Using isolates for I/O-bound work (network calls) that already doesn't block the main isolate — isolates only help with CPU-bound work.
- ×Passing non-message-safe objects (like a class holding a `BuildContext`) across the isolate boundary.
Interview Tips
- →Mention `compute()` by name — it's the practical, most-used entry point and shows real usage, not just textbook knowledge.
Related Questions
How does Flutter manage memory, and how do you avoid leaks?
Dart uses automatic garbage collection, so you don't free memory manually — leaks in Flutter almost always come from long-lived objects (controllers, streams, listeners) holding references that prevent disposed widgets' resources from being collected.
What are platform channels and why are they needed?
Platform channels are Flutter's message-passing bridge to native platform code (Kotlin/Java on Android, Swift/Objective-C on iOS) — used whenever you need a platform API or native SDK that has no Dart equivalent.