Imgkl / EventFlux

A Dart package for efficient handling of server-sent event streams with easy connectivity and data management.
https://pub.dev/packages/eventflux
MIT License
25 stars 8 forks source link

EventFlux instance should have dispose() or close() method #12

Closed jangruenwaldt closed 5 months ago

jangruenwaldt commented 7 months ago

For example, in the following line is a StreamSubscription that is never cancelled, this could cause memory leaks:

      ///Applying transforms and listening to it
      data.stream
          .transform(const Utf8Decoder())
          .transform(const LineSplitter())
          .listen(...)

Things like this and the other state should be cleaned up when dispose() is called.

Imgkl commented 6 months ago

Doesn't closing the client, automatically close this data stream as well? Also there's no close/disconnect method for StreamedResponse class

jangruenwaldt commented 6 months ago

When calling .listen(...) on a stream, a StreamSubscription is created:

https://api.flutter.dev/flutter/dart-async/StreamSubscription-class.html

This subscription should be cancelled once it is not needed anymore.

For example, once the connection is lost and we have to reconnect, I think this code is called again, and a new subscription is created. (IIRC - please double check though 😄) But in general, its a good practice to keep track of stream subscriptions, and cancel them on dispose().

Imgkl commented 6 months ago

@jangruenwaldt Thanks for the resource, I found it useful.

I found what you were mentioning. I've fixed it. Should be available in the next release.

Imgkl commented 6 months ago

Keeping this issue open still the fix is released.

Imgkl commented 5 months ago

This is fixed on the latest version of EventFlux, v1.7.0.