Thread and Isolate with Flutter

Olivier Brand
Flutter Community
Published in
5 min readSep 27, 2021

--

Who needs another overview on using threads in Flutter? I would like to go over the main problems a developer may face when developing Flutter apps, but more importantly understand how threading works, what problems we are trying to solve, how efficient code can be written as a result.

Isolates

An isolate is a thread that has an event loop that continuously processes events in its own memory space. In effect when the main dart function executes, it executes in an isolate that scans for available events and hangs when none are available, an opportunity for the system to decide to run the garbage collector for example.

Dart can execute multiple threads by spawning additional isolates. Creating more isolates can be useful for heavy computation processing but most Flutter apps do not need spawning additional isolates unless it becomes an issue and impacts the frame rate.

Languages such as Java, C++ have multi-threading built-in but it comes at performance costs, especially when it comes to garbage collection. With one thread running and a single memory space per garbage collector, it becomes very efficient as predictable (no mutation possible during garbage collection cycles)

Event loop

--

--

Olivier Brand
Flutter Community

I am passionate about mobile, especially designing end to end processes for delivering solid apps and supporting backend systems.