Flutter & Dart (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
How does Garbage Collection work in Dart?
senior LevelMemory Management
In Simple Words: Dart uses a generational garbage collector with two spaces:
- Young Generation (Scavenger): For short-lived objects (e.g. Flutter widgets created during rebuilds). Uses Cheney's copying algorithm to reclaim dead objects in sub-milliseconds without stopping the world.
- Old Generation (Mark-Sweep / Mark-Compact): For objects that survive multiple young-gen cycles (singletons, state stores). Runs infrequently in the background to avoid UI stutter.