Search code examples
flutterdartgoogle-cloud-firestorerxdart

Do I need to dispose Firestore document snapshot or just the listener


Let's say I have the following:

StreamSubscription _exampleQuery;
_exampleQuery = dbUsers
        .document(accID)
        .snapshots()
        .listen((DocumentSnapshot _userDocSnap) {}

When I call:

_exampleQuery.cancel();

Is it possible, that the snapshot listener is somehow still active? It seems like firestore bills me for still active subscriptions that are still active & reading documents.

I am familiar with firestore billing, and know that certain unexpected things may couse reads, but I am almost 100% certain that my subscriptions ain't getting canceled properly.


Solution

  • If you cancel a listener, then it will not incur any more document reads from that point on. If you have an MVCE that proves otherwise, please file a bug report with Firebase support so they can validate it. But I would be absolutely shocked if there was a bug here. You are likely incurring extra reads some other way, such as via the console.