Question
Future vs Stream for Continuous Polling: Which Keeps Memory Usage in Check?
Neel Echo
0 reputation · 07 Jun 2020, 02:38 UTC
54.5K views0
Goal
Implement a background service that polls a REST endpoint every minute and processes the response in a Flutter app.
Constraints
The service runs for hours, so memory consumption and subscription lifecycle must be managed carefully. The implementation should be easy to debug and maintain.
Unresolved Decision
Should the polling logic use a single Future per request, or a Stream that emits each poll result?
Specific Questions
- How does the lifecycle of a
StreamControllerimpact memory when emitting one event per minute over long periods? - What are the best practices for closing a
Streamto prevent leaks in a long‑running background service? - Does a
Future-based approach simplify debugging compared to aStream-based approach in this scenario?