The Firebase Database client keeps a copy of all data that you're listening to in memory of your app. Once you remove the last listener for a location, as we have already discussed here, the data is removed from memory.
When we are speaking about Firebase, everything is about listeners and as a quick response to your question, no, a listener doesn't take huge memory and you can use as many listeners as you want, if remove them correctly.
Using addListenerForSingleValueEvent() means that:
Add a listener for a single
change in the data at this location.
So there is no need to remove the listener.
If you have used for example, ref.keepSynced(true)
, all data at ref
location would be kept in memory, and kept up to date.
If you enable persistence
, the client will also persist active and recent data to disk.