agrosner / DBFlow

A blazing fast, powerful, and very simple ORM android database library that writes database code for you.
MIT License
4.88k stars 598 forks source link

CursorWindowAllocation crash #393

Closed kaeawc closed 8 years ago

kaeawc commented 9 years ago

Found this crash occurring very intermittently on a model that extends BaseCacheableModel. Seems like a cursor isn't being closed in some edge case http://stackoverflow.com/questions/12029437/android-mysqlite-cursorwindowallocationexception-crash

Stack Trace:

_________________________________
0   android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. 
1       at android.database.CursorWindow.<init>(CursorWindow.java:108)
2       at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:198)
3       at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:139)
4       at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133)
5       at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:197)
6       at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:237)
7       at com.raizlabs.android.dbflow.sql.SqlUtils.convertToCacheableModel(SqlUtils.java:186)
8       at com.raizlabs.android.dbflow.sql.SqlUtils.querySingle(SqlUtils.java:221)
9       at com.raizlabs.android.dbflow.sql.language.BaseModelQueriable.querySingle(BaseModelQueriable.java:40)
10      at com.raizlabs.android.dbflow.sql.language.Where.querySingle(Where.java:366)
11      at com.our.app.data.model.queryhandler.UserInfoQueryHandler.getData(UserInfoQueryHandler.java:39)
agrosner commented 8 years ago

thanks I found a few probably causes for this. thanks. develop should have the fixes now.

tjuric commented 8 years ago

I've also encountered similar error within my BaseAdapter class on the line where FlowCursorList is instantiated (adapter's constructor).

flowCursorList = new FlowCursorList<>(20, selectFrom);

This instantiation is called in Activity's onCreate() method, and I've reproduced this only by starting/destroying the activity multiple times - about 50 times fast starting/destroying activity (with the RecyclerView).

stacktrace:

Caused by android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. # Open Cursors=10 (# cursors opened by this proc=10)
       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 com.raizlabs.android.dbflow.list.FlowCursorList.setCacheModels(FlowCursorList.java:92)
       at com.raizlabs.android.dbflow.list.FlowCursorList.<init>(FlowCursorList.java:54)
       at com.raizlabs.android.dbflow.list.FlowCursorList.<init>(FlowCursorList.java:38)

Could it be the same cause?

NOTE: I haven't test the develop version. This encountered on the latest release version 2.2.1.