2

I am getting some data from the Realtime Database for Android. Sometimes I got a crash with this message:

java.lang.RuntimeException: Firebase Database encountered an OutOfMemoryError. You may need to reduce the amount of data you are syncing to the client (e.g. by using queries or syncing a deeper path). `
The problems here are:

  1. I am not sure what data and what call to make that exception to optimize it. How to find the call or portion of the data that must be optimized?
  2. The second problem is that this crash happens not on all devices + it does not happen all the time.

Could you give me any suggestions on fixing that?

1 Answer 1

2

As the error message states, you are reading too much data in a single database call.

  1. If you don't know which is the exact query that produces that error, there are two possible solutions here that should be implemented in order to solve the problem. The first one is to limit the data by calling limitToFirst(int limit) or limitToLast(int limit). The second solution would be to implement pagination. In each case, it doesn't matter which was the query that produces the error, since all queries are already limited.

  2. That's the expected behavior since not all devices are the same. Besides that, if you have multiple users, maybe they are reading data from different locations, that have different sizes.

Always remember, try to read only the data fits on the user's screen, and nothing more.

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

2 Comments

Hey Bob. Can I help you with other information?
Thank you for the answer. I have the same issue now and looking to pagination case to solve that. I have to download aprox. large data bundles (5-6MB) to store it locally as offline cache.

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.