0

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.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Deepak Goyal
  • 4,747
  • 2
  • 21
  • 46
  • 1
    This might be your only option: https://stackoverflow.com/questions/38281761/clear-firebase-persistence-after-logout – Frank van Puffelen Jul 19 '23 at 21:51
  • @FrankvanPuffelen I checked the DB file stored under /databases/ in the app directory. It has a `trackedQueries` table. This table contains the paths along with queryParams on which keepSynced is added. - I deleted the row where the queryParams is '{}'. - I deleted all the rows from `serverCache` table also. But no luck. Anything else that I can do to solve this issue? – Deepak Goyal Jul 20 '23 at 16:16
  • The database structure is not documented, so I'd recommend not making edits but just delete it in its entirety (while the app is not running, or at least is not accessing the database yet). – Frank van Puffelen Jul 20 '23 at 19:13
  • I don't want to always delete it. I just want to delete it when there is an entry in the database file for the keepSynced on the root database reference. – Deepak Goyal Jul 21 '23 at 09:35

0 Answers0