'unsubscribe' best practices / Firebase / AngularFire2

222 views
Skip to first unread message

Jörg Wiesmann

unread,
Feb 22, 2018, 5:59:17 PM2/22/18
to Firebase Google Group
Hi,

i would like to understand what might be the best practice to unsubscribe from my observables.
Right now i am doing it more or less instantly if a Component gets destroyed, or i am not doing it at all (for like super frequent pages / components)

In some cases i can see why it would be useful to unsubscribe, but lets say i have some activities in my application. 
The first time loading takes a little while, but after that it is super fast. But only if i do not unsubscribe.

So what kind of numbers / experience are good values? 
Can i keep up like 100 subscriptions without worrying about it? Should i better unsubscribe all of them? 
What would you suggest? 

Thank you :)

Kato Richardson

unread,
Feb 23, 2018, 11:33:45 AM2/23/18
to Firebase Google Group
Hi Jorg,

As a general rule, if you are subscribing within a component, do this on OnInit, and then unsubscribe in the OnDestroy method for your component.

If you have a data set that is frequently accessed by multiple users, then create a service and subscribe there. Probably no need to unsubscribe from this as long as you keep the query size reasonable (i.e. it's not going to fill available memory). Otherwise, you'd need to come up with some scheme based on your use case for when the data is no longer useful.

☼, Kato


--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/4da9c80d-e96d-4a11-b700-6ed4f8fae79b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Reply all
Reply to author
Forward
0 new messages