Let’s Talk About Memory Leaks In Dart And Flutter
summary
Explains why Dart’s generational GC and mark‑and‑sweep leave objects reachable (for example passing a BuildContext into long‑lived callbacks or keeping static caches) and shows concrete fixes: cancel streams, detach listeners, limit caches, use weak references and Finalizer for native FFI cleanup, prefer BytesBuilder over repeated string concatenation, and add tests that run leak_tracker and export DevTools snapshots. Recommends static analysis and shows a project scan that finds 558 memory issues, plus using DevTools and Leak Tracker in CI.
AI-written summary · about
chapters (17)
- 0:00Introduction and setup
- 3:06What to expect from this talk
- 4:10Memory leaks vs memory bloating
- 7:39Dart VM and garbage collection
- 11:36Disposable and risky objects
- 13:01Context references in closures
- 15:53Static variables and memory
- 17:18Weak references explained
- 19:27Weak maps and Finalizers
- 21:57Finalizer use cases
- 22:19Streams and listeners
- 23:26Widget lifecycle cleanup
- 24:31String concatenation optimization
- 25:57Lazy builders and memory
- 26:59Tooling for memory leaks
- 29:06Static analysis and DCM
- 30:35Book promotion and closing
