1

I have a memory problem that I can't figure out.

12-17 00:03:10.603: E/AndroidRuntime(19910): android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. # Open Cursors=723 (# cursors opened by this proc=723)

This happens only when I refresh the page 15-20 times(each time make something like 30 query).

        Cursor c;

        for(w = 0; w < 30; w++)
        {   
            ...
            c = dataBase.fetchA();  

            int valueColIncome = c.getColumnIndex(myDatabase.IEMetaData.IE_VALUE); 

            if(c.moveToFirst())
            {  
                do              
                {   
                    ...
                }while(c.moveToNext()); 
            }

            c = dataBase.fetchB();

            if(c.moveToFirst())
            {  
                do              
                {                   
                    ...
                }while(c.moveToNext()); 
            }
            ...                
        }
        c.close();

I also try to create a cursor every loop in the for and then close it, but nothing has changed. When I refresh this activity more than 15 times the exception is throw.

Blodhgard
  • 9,130
  • 3
  • 24
  • 36

2 Answers2

0

Close your cursors!:

    for(w = 0; w < 30; w++)
    {   
        ...
        c = dataBase.fetchA();  

        int valueColIncome = c.getColumnIndex(myDatabase.IEMetaData.IE_VALUE); 

        if(c.moveToFirst())
        {  
            do              
            {   
                ...
            }while(c.moveToNext()); 
        }
        c.close();

        c = dataBase.fetchB();

        if(c.moveToFirst())
        {  
            do              
            {                   
                ...
            }while(c.moveToNext()); 
        }
        c.close();
        ...                
    }

Most often the cause for this error are non closed cursors.

Jorgesys
  • 124,308
  • 23
  • 334
  • 268
0

@Jorgesys answer is mostly done. I think it should solve the problem.
The reason is Cursor is not close for every time, but it is better to have

for() {
Cursor c;
.....
c.close();
}

One thing to remember is that, the android Cursor windows is limited to 2Mb.
So when you query the data (especially the BLOB), the size should not be bigger the limitation.
To solve that problem, divide you query into smaller part or think again the db design

kidnan1991
  • 366
  • 2
  • 12