Skip to content
Advertisement

App crash with GC When an object added to firebase – Android Studio

Hello I have an Android app

when an update ( Insert new data in firebase or update an attribute ) is done in firebase the app will crash for 15-30 sec.

when I checked the log, it show that’s in that time the GC is working and it takes a lot of time to do his work so the app crashed a lot of time and on the phone, you can’t do anything till GC finishes there work, I don’t have so much data in my database also my application is not that bigger.

You can see the log here :

JavaScript

here’s what log is saying

and this is my code how i receive data from firebase :

JavaScript

any suggestion to solve this?

Advertisement

Answer

The app will crash.

It’s the expected behavior since reading 1000+ nodes at once can be considered a lot of data, that most likely doesn’t fit into the memory. Besides that, I see that you’re looping through the children three times. This means that under Orders/City there are also other nodes present, this means even more data to read. In the Realtime Database, when you attach a listener to a particular location in the database, you read (download) that node along with all the children beneath it. In such cases, it’s best to denormalize the data. This means that you should create another node that should contain only the data you are interested in a flat list of nodes. Besides that, it’s best the limit the amount of data that you read by calling Query#limitToFirst(int limit) or Query#limitToLast(int limit) according to your needs. Besides that, it’s also recommended to implement pagination.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement