Out of memory in BlackBerry OS 5.0 SQLite Out of memory in BlackBerry OS 5.0 SQLite sqlite sqlite

Out of memory in BlackBerry OS 5.0 SQLite


In BlackBerry OS 5.0, the available memory for Sqlite is quite limited - 512kb. This means building lots of statements, or inserting large data, can easily consume all memory availble to Sqlite, even if the device reports large amounts of free memory.
It looks like you are constructing the insert statement string yourself, and doing it for each new row. You would save yourself a lot of memory by using a prepared statement, and then binding the values into the statement. This also has the advantage of avoiding sqlite injection issues, intentional or accidental.

Instead of directly entering the string values, create the statement outside of the loop, and then inside the loop reset and bind the same statement object:

Statement statement = database.createStatement(    "INSERT INTO messages (message_id,message,status,message_type_id,"+    "response,date_added,sender,office,sent_on,phoneno) VALUES (?,?,?,?,?,?,?,?,?,?)");statement.prepare();for (int i = 0; i < messages.size(); i++) {    Messages m = (Messages) messages.elementAt(i);        statement.reset();    statement.bind(1, m.getMessageId());    statement.bind(2, m.getMessage());    // and so on, for all the arguments    statement.execute();}