Reputation: 621
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:
Could you give me any suggestions on fixing that?
Upvotes: 2
Views: 365
Reputation: 138824
As the error message states, you are reading too much data in a single database call.
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.
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.
Upvotes: 2