r/flutterhelp • • 3d ago

RESOLVED Flutter help

I recently learned about Dart isolates, and they are incredible for handling heavy workloads by running tasks on a separate isolate away from the main thread.

However, when we spawn a new isolate, does it actually create a new operating system thread? I am quite confused, as AI models keep agreeing with me that it conceptually creates a new thread without providing a definitive, underlying reason. Since Dart is fundamentally a single-threaded language where the main execution runs in a single isolate, does spawning a new isolate actually entail creating another thread under the hood? I would love to understand the precise mechanics of what happens at a lower level when a new isolate is spawned.

1 Upvotes

7 comments sorted by

2

u/svprdga 3d ago

Yes, a new thread is created separate from the main thread where Dart runs. The special particularity is that it has assigned a segment of memory independent of the main process.

2

u/SpellBig8198 3d ago

You should also know that there is a price to pay every time you spawn an isolate, so you should only do it when you really need it, e.g. when processing a large file or running a complex algorithm. Most of the time, you don't need isolates at all.

1

u/Solid-Exercise-225 3d ago

Yess I read it, major confusion was the new thread part

1

u/Beginning_Fill6201 3d ago

Just don't create also handle it close it when the process is done similar to http client

1

u/50u1506 3d ago

So from what I've read(asked AI some particular questions for the most part lol), yes a new OS thread is created per isolate.

Each heap allocated object is also per isolate, with no way to share them between Isolates.

1

u/50u1506 3d ago

I think that is the case, I will Google or AI and get back to u lol