Android Question Error in Keystore GetSimple

sconlon

Active Member
Licensed User
Longtime User
I'm using a keystore in my app and am getting the following error consistently after some minutes of operation.

"An error has occurred in sub:keyvaluestore_getsimple. android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. # Open Cursors=848 (#cursors opened by this proc=848)"

The GetSimple sub code is

B4X:
Public Sub GetSimple(Key As String) As String
    Dim c As Cursor = getCursor(Key)
    If c.RowCount = 0 Then Return ""
    c.Position = 0
    Dim res As String = c.GetString2(0)
    c.Close
    Return res
End Sub

So could this error be caused by repeated calls and return when c.Rowcount = 0 and the cursor isn't closed? In which case I should c.Close before the Return "".
 

sconlon

Active Member
Licensed User
Longtime User
I have used the new version of KeyValueStore and have to report that the error is still happening. I have logged each entry to GetSimple and it only logs an entry about 10 times before the error is reported. In each case I am getting the same key but I don't think this is significant as it is the only key that is requested by the app when it is running and (effectively) doing nothing. This key (SetUAP) does exists and is either 0 or 1.

I have attached the log snippet below.

B4X:
Getting key: setUAP
keyvaluestore_getsimple (java line: 236)
android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. # Open Cursors=862 (# cursors opened by this proc=862)
    at android.database.CursorWindow.<init>(CursorWindow.java:104)
    at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:198)
    at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:162)
    at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:156)
    at anywheresoftware.b4a.sql.SQL$CursorWrapper.getRowCount(SQL.java:313)
    at mario.server.keyvaluestore._getsimple(keyvaluestore.java:236)
    at mario.server.displayorders._showstatus(displayorders.java:9828)
    at mario.server.displayorders._smstimer_tick(displayorders.java:9980)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
    at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
    at android.os.Handler.handleCallback(Handler.java:605)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4482)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
    at dalvik.system.NativeStart.main(Native Method)
android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. # Open Cursors=862 (# cursors opened by this proc=862)
 
Upvote 0

sconlon

Active Member
Licensed User
Longtime User
I examined my own code for unclosed cursors and found some that seemed to have caused the problem. What lead me astray originally was the error message reporting "(# cursors opened by this proc=862)" which I assumed was the GetSimple 'proc' but it seems to refer to the application or at least the calling module.

Anyway, it's fixed now and sorry for casting doubt on your code!
 
Upvote 0
Top