Firebase数据库OutofMemory错误

时间:2017-11-22 08:37:52

标签: android firebase firebase-realtime-database out-of-memory firebase-storage

我想要获取我所有的json孩子,所以我可以离线我的应用程序。我的应用程序第一次启动时进行同步。由于它在数据库中包含太多数据,我的应用程序多次崩溃,并且无法获取所有数据。

  

致命的例外:主要                                                                               过程:com.manish.firebaseexample,PID:12234                                                                               java.lang.RuntimeException:Firebase数据库遇到OutOfMemoryError。您可能需要减少要同步到客户端的数据量(例如,通过使用查询或同步更深的路径)。见https://firebase.google.com/docs/database/ios/structure-data#best_practices_for_data_structurehttps://firebase.google.com/docs/database/android/retrieve-data#filtering_data                                                                                   在com.google.android.gms.internal.zzdyi.run(未知来源)                                                                                   在android.os.Handler.handleCallback(Handler.java:733)                                                                                   在android.os.Handler.dispatchMessage(Handler.java:95)                                                                                   在android.os.Looper.loop(Looper.java:146)                                                                                   在android.app.ActivityThread.main(ActivityThread.java:5602)                                                                                   at java.lang.reflect.Method.invokeNative(Native Method)                                                                                   在java.lang.reflect.Method.invoke(Method.java:515)                                                                                   在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1283)                                                                                   在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)                                                                                   at dalvik.system.NativeStart.main(Native Method)                                                                                引起:java.lang.OutOfMemoryError                                                                                   at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:94)                                                                                   在java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:145)                                                                                   在java.lang.StringBuilder.append(StringBuilder.java:216)                                                                                   at bma.toString(:com.google.android.gms.DynamiteModulesC@11746036:11)                                                                                   在bkq.a(:com.google.android.gms.DynamiteModulesC@11746036:82)                                                                                   在bkv.run(:com.google.android.gms.DynamiteModulesC@11746036:9)                                                                                   at java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:422)                                                                                   在java.util.concurrent.FutureTask.run(FutureTask.java:237)                                                                                   at java.util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.access $ 201(ScheduledThreadPoolExecutor.java:152)                                                                                   at java.util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)                                                                                   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)                                                                                   at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:587)                                                                                   在java.lang.Thread.run(Thread.java:841)

我的数据库图片

enter image description here

Varieties Details

 refDatabase = FirebaseDatabase.getInstance().getReference().child("INT").child("varieties");
    refDatabase.keepSynced(true);


    refDatabase.getRef().addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            Log.d(TAG,""+dataSnapshot.toString());
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.d(TAG,databaseError.getMessage());
        }
    });

As" image"数据包含Base64编码图像。

1 个答案:

答案 0 :(得分:2)

正如错误消息所示,您检索的数据超出了手机内存中可扩展的数据。有两种解决方法。

  
      
  1. 释放手机的内存以保存更多数据。
  2.   
  3. 使用其中一种过滤方法过滤数据。
  4.   

请参阅有关Firebase中过滤数据的offical documentation