0

My app needs 100% to sync up the data to Firebase Database and it must working ok even it goes offline, So I enabled offline capabilities as this official document described.

The problem was after use the app for a while the app was crashed even reinstalled the app

I was walked through the document as provided in the stack trace there is no read on my app only write to Firebase Database

Fatal Exception: 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). See https://firebase.google.com/docs/database/ios/structure-data#best_practices_for_data_structure and https://firebase.google.com/docs/database/android/retrieve-data#filtering_data
   at com.google.android.gms.internal.zzdok.run(Unknown Source)
   at android.os.Handler.handleCallback(Handler.java:815)
   at android.os.Handler.dispatchMessage(Handler.java:104)
   at android.os.Looper.loop(Looper.java:207)
   at android.app.ActivityThread.main(ActivityThread.java:5728)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749) Caused by java.lang.OutOfMemoryError: Failed to allocate a 48 byte allocation with 1280 free bytes and 1280B until OOM
   at bjf.a(:com.google.android.gms.DynamiteModulesC@11951440:37)
   at bjf.b(:com.google.android.gms.DynamiteModulesC@11951440:45)
   at bjf.a(:com.google.android.gms.DynamiteModulesC@11951440:41)
   at bjf.b(:com.google.android.gms.DynamiteModulesC@11951440:45)
   at bjf.a(:com.google.android.gms.DynamiteModulesC@11951440:41)
   at bjf.b(:com.google.android.gms.DynamiteModulesC@11951440:45)
   at bjf.a(:com.google.android.gms.DynamiteModulesC@11951440:41)
   at bjf.b(:com.google.android.gms.DynamiteModulesC@11951440:45)
   at bjf.a(:com.google.android.gms.DynamiteModulesC@11951440:41)
   at bjf.b(:com.google.android.gms.DynamiteModulesC@11951440:45)
   at bjf.a(:com.google.android.gms.DynamiteModulesC@11951440:41)
   at bjf.b(:com.google.android.gms.DynamiteModulesC@11951440:45)
   at bjf.a(:com.google.android.gms.DynamiteModulesC@11951440:41)
   at bjf.b(:com.google.android.gms.DynamiteModulesC@11951440:45)
   at bjf.a(:com.google.android.gms.DynamiteModulesC@11951440:41)
   at bjf.b(:com.google.android.gms.DynamiteModulesC@11951440:45)
   at bjf.a(:com.google.android.gms.DynamiteModulesC@11951440:41)
   at bjf.a(:com.google.android.gms.DynamiteModulesC@11951440:34)
   at bgz.a(:com.google.android.gms.DynamiteModulesC@11951440:82)
   at bhe.run(:com.google.android.gms.DynamiteModulesC@11951440:9)
   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
   at java.lang.Thread.run(Thread.java:818)
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
a-rohim
  • 506
  • 1
  • 5
  • 19
  • You seem to be forcing too much data into memory. The proper solution is to reduce the amount of data you load into memory. Alternatively: set a large heap size as shown here: https://stackoverflow.com/questions/37734624/out-of-memory-error-when-using-firebase. Also see some of these: https://www.google.com/search?q=site:stackoverflow.com+firebase+OutOfMemoryError – Frank van Puffelen Jan 01 '18 at 18:59
  • Thank you, I tried, it kind of work for some devices I think to root problem is the data is too big is not good fit for some devices as this document described (https://firebase.google.com/docs/firestore/manage-data/enable-offline) [ This feature caches a copy of the Cloud Firestore data that your app is actively using, so your app can access the data when the device is offline. ] I have almost 50k records. – a-rohim Jan 03 '18 at 08:42
  • The Firebase Realtime Database is a Cloud-first database that continues to work when the user is offline. Treating it as a full offline-first database is a recipe for headaches. – Frank van Puffelen Jan 03 '18 at 14:45
  • The problem was fixed, we just turn off keepSynced flag https://firebase.google.com/docs/database/android/offline-capabilities [The Firebase Realtime Database client automatically downloads the data at these locations and keeps it in sync even if the reference has no active listeners.] – a-rohim Jan 05 '18 at 04:44
  • The sole purpose of calling `keepSynced(true)` on a location is to keep that location synchronized when there are no (other) active listeners. Setting `keepSynced()` on the root and enabling persistence are a common cause of problems, hence my previous comment on how to think of the Firebase Realtime Database's offline capabilities. – Frank van Puffelen Jan 05 '18 at 05:35

0 Answers0