I have a service that uses a StreamController.broadcast() and is shared among multiple BLoCs. Since multiple BLoCs/widgets may be using the stream at the same time, I can’t close the StreamController when a widget is disposed.
<code>class SharedService {
StreamController<MyEvent> _controller = StreamController<MyEvent>.broadcast();
Stream<MyEvent> get events => _controller.stream;
// ...
}
</code>
<code>class SharedService {
StreamController<MyEvent> _controller = StreamController<MyEvent>.broadcast();
Stream<MyEvent> get events => _controller.stream;
// ...
}
</code>
class SharedService {
StreamController<MyEvent> _controller = StreamController<MyEvent>.broadcast();
Stream<MyEvent> get events => _controller.stream;
// ...
}
The documentation says a broadcast stream does not buffer events, so
is it safe to leave the broadcast StreamController open, or will it cause memory leaks?