0

My app is crashing due to high amount of data that it needs to sync. Firebase crashanalytics tells me:

Firebase Database encountered an OutOfMemoryError. You may need to reduce the amount of data you are syncing to the client

My code is like this:

public static DatabaseReference getRefFirebase() {
        if (mDatabase == null) {
            mDatabase = FirebaseDatabase.getInstance();
            mDatabase.setPersistenceEnabled(true);
            mDatabase.getReference().keepSynced(true);
        }


        return mDatabase.getReference();
    }

So its syncing all the database. I know that this is not needed for all functions on the app but I dont know how to solve it yet. I looked for a SYNC request, so it could only sync once, but apparently Firebase has no such method. Anybody has a similar issue that could help me?

1 Answer 1

1

With that code you've written, you're asking the SDK to synchronize the ENTIRE contents of your database every time something changes. This means that the entire contents of memory must fit in memory at all time. This is probably not a good idea, unless you know your database is constrained in size.

Consider instead just keeping a portion of the database synchronized all the time, and only if you understand its memory requirements at all times. If the part of the database could grow unbounded, you almost certainly don't want to do this at all. Since you haven't really said what your goal is here, you might want to consider just not doing this until you have a clear goal for constant synchronization.

Even if you synchronize just once (by using addEventListenerForSingleEvent), the entire contents of the reference still need to fit entirely in memory at once. So think carefully about what you're trying to do here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.