Sreekanth Karumanaghat
Sreekanth Karumanaghat

Reputation: 3403

Does Firebase listeners take up huge memory?

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?

Upvotes: 0

Views: 1051

Answers (2)

Alex Mamo
Alex Mamo

Reputation: 138824

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.

Upvotes: 1

Shilpy Samaddar
Shilpy Samaddar

Reputation: 69

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.

Upvotes: 1

Related Questions