有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Firebase setPersistenceEnabled。导致大量内存使用

我遇到了一个奇怪的问题

我注意到我的firebase Android应用程序变得有点迟钝,所以决定对其进行评测。几分钟之内,内存使用量就增长到了500MB。我暂停了探查器查看发生了什么,所有的电话都来自com。谷歌。安卓gms,当我查看CPU使用情况时,它显示firebase数据库的高使用率

我将问题追溯到调用“setPersistenceEnabled(true);”在我的数据库实例上,如果我关闭这个,性能会恢复,RAM使用会显著降低

  • 当我启动应用程序时,我有一个网络连接,几分钟内内存使用量达到500MB

  • 当我启动应用程序时,我没有网络连接,几分钟内内存使用量也达到了500MB

  • 我没有在启动时写入任何数据,只是从特定节点读取一些数据

  • 如果我注释掉对firebase数据库的所有调用,只留下存根,RAM的使用情况就会出现很好

  • 如果我重新启用任何一种进行任何类型数据库交互的方法,RAM的使用量在几分钟内就会达到500MB

我几乎认为内部出现了严重问题,我应该关闭应用程序并重新启动

医生说

When you enable disk persistence, your app writes the data locally to the device so your app can maintain state while offline, even if the user or operating system restarts the app.

而且

By enabling persistence, any data that the Firebase Realtime Database client would sync while online persists to disk and is available offline, even when the user or operating system restarts the app. This means your app works as it would online by using the local data stored in the cache. Listener callbacks will continue to fire for local updates.

The Firebase Realtime Database client automatically keeps a queue of all write operations that are performed while your app is offline. When persistence is enabled, this queue is also persisted to disk so all of your writes are available when the user or operating system restarts the app. When the app regains connectivity, all of the operations are sent to the Firebase Realtime Database server.

有人有什么想法吗


共 (0) 个答案