I have the keepSynced on database reference like below.
ref.keepSynced(true);
In the database reference user adds the records. Some users have a large number of records. Using the keepSynced reference gives OOM error.
The solution is to use the keepSynced on the small amount of data. So I used keepSynced on the query instead of database reference.
ref.orderByChild('child').limitToLast(100).keepSynced(true);
I released a new app version with the above solution. But it has the following issue.
- Users already have the previous app version installed with keepSynced on the database reference.
- After updating the app with keepSynced on the query, the app started crashing.
I tested this at my end.
- If a fresh app (no previous version on the device) is installed with a query solution then it works fine.
- If an updated version is installed then it keeps crashing.
Crash:
Fatal Exception: java.lang.RuntimeException: Uncaught exception in Firebase Database runloop (20.2.0). If you are not already on the latest version of the Firebase SDKs, try updating your dependencies. Should this problem persist, please file a report at https://github.com/firebase/firebase-android-sdk
at com.google.firebase.database.android.AndroidPlatform$1$1.run(AndroidPlatform.java:99)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:210)
at android.os.Looper.loop(Looper.java:299)
at android.app.ActivityThread.main(ActivityThread.java:8252)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:559)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:954)
Caused by java.lang.RuntimeException: java.lang.OutOfMemoryError: Failed to allocate a 16 byte allocation with 1183242 free bytes and 1155KB until OOM, target footprint 536870912, growth limit 536870912; giving up on allocation because <1% of heap free after GC.
at com.google.firebase.database.core.persistence.DefaultPersistenceManager.runInTransaction(DefaultPersistenceManager.java:244)
at com.google.firebase.database.core.SyncTree.addEventRegistration(SyncTree.java:549)
at com.google.firebase.database.core.SyncTree.keepSynced(SyncTree.java:857)
at com.google.firebase.database.core.Repo.keepSynced(Repo.java:772)
at com.google.firebase.database.core.Repo.keepSynced(Repo.java:767)
at com.google.firebase.database.Query$4.run(Query.java:267)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:463)
at java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:307)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
at java.lang.Thread.run(Thread.java:1012)
I have tried adding the following but no luck.
ref.keepSynced(false);
keepSynced
works only on the instance level not on the app level. See Firebase SDK Remove All "keepSynced" References
So I'm not sure why the app is crashing.