0

Does Firebase listeners like this take up huge heap memory?

ref.addListenerForSingleValueEvent(new com.google.firebase.database.ValueEventListener() {
    @Override
    public void onDataChange(com.google.firebase.database.DataSnapshot snapshot) {
    }
});

At least when the snapshot is taken?

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
Sreekanth Karumanaghat
  • 3,383
  • 6
  • 44
  • 72
  • 1
    Currently your question is not really specific. Maybe change it to: "How much heap memory do firebase listeners take up?" And maybe add samples of the data you put the listeners on. Memory use should be different for a listener on a single string or a listener on a complex object. – André Kool Feb 26 '18 at 10:42

2 Answers2

1

addListenerForSingleValueEvent() will take snapshot or sync data only once when called, if there is a change in the data of that node and internet connection is available.

addValueEventListener() will take snapshot or sync data from node whenever there is a change in data of that node and internet connection is available.

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
1

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.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193