Room CursorWindowAllocationException

1. 崩溃日志

android.database.CursorWindowAllocationException: Could not allocate CursorWindow '/data/user/0/cn.xxx.xxx/databases/xxx.db' of size 2097152 due to error -13.
	at android.database.CursorWindow.nativeCreate(Native Method)
	at android.database.CursorWindow.<init>(CursorWindow.java:139)
	at android.database.CursorWindow.<init>(CursorWindow.java:120)
	at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:202)
	at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:147)
	at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:140)
	at yd.d.m(SourceFile:21)
	at cn.xxx.control.y.y0(SourceFile:1)
	at e5.y.p(SourceFile:230)
	at e5.y.l(SourceFile:1)
	at e5.y.E(SourceFile:1)
	at cn.xxx.cluster.classin.viewmodel.SessionViewModel$d.invokeSuspend(SourceFile:42)
	...

2. 触发原因

  • Room 对应的 Sqlite 数据库,其对 CursorWindows 分配的大小是有限制的,最大为 2M,超过之后会发生上述崩溃闪退现象(偶现且难以复现的 bug

3. 解决方法

  • 需要业务方梳理这块的业务,优化数据库的调用,如果明确知道在一个方法里面会调用多个数据库的方法,需要让 controller 提供新的方法,且这个 controller 层的方法需要添加 @Transaction 进行注解,从而保证在同一个事物内进行数据库操作,以此避免 CursorWindows 大小超过 2M

4. 参考文章

  • https://github.com/android/architecture-components-samples/issues/289
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值