使用RxJava适配器在Room上分配2048KB光标窗口失败。

4

我在我的应用程序中使用版本为1.0.0的RxJava2房间。之前我使用的是Realm,一切都很好。现在当我迁移到Room时,我会遇到类似的随机崩溃:

Fatal Exception: android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. 
       at android.database.CursorWindow.<init>(CursorWindow.java:109)
       at android.database.CursorWindow.<init>(CursorWindow.java:100)
       at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:198)
       at android.database.sqlite.SQLiteCursor.clearOrCreateWindow(SQLiteCursor.java:301)
       at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:139)
       at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133)
       at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:197)
       at android.database.AbstractCursor.moveToNext(AbstractCursor.java:245)
       at android.arch.persistence.room.InvalidationTracker.run(InvalidationTracker.java:372)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:841)

有时候甚至没有空间提及它。我没有直接使用任何游标,只是通过 Room 和第三方库(在迁移期间未更改)间接使用。

我已经检查了 Room 生成的代码,它看起来都会正确关闭游标。

对于发生的情况和如何调试这些崩溃,你有什么想法吗?


此外,我已设置StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()。detectLeakedSqlLiteObjects()。detectLeakedClosableObjects()。penaltyLog()。build());,并且在日志中没有看到任何异常。 - MikhailKrishtop
我也遇到了同样的问题。你找到任何解决方案了吗? - codeskraps
1个回答

1
原来问题出在RxJava的.subscribeOn(Schedulers.io())对于RxJava Room适配器中的Flowable响应。显然,它会启动线程但从未释放它们。 我已经将固定线程池上的Schedulers.io()替换为最多20个线程,并且问题得到了解决。

1
嘿,我遇到了类似的问题,但是是在使用LiveData时 - 没有使用RX。你有什么想法或建议来解决这个问题吗? - dasfima

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接