3

From performance point of view, regardless of other constraints:

What is the cost of opening a SQLiteDatabase in the whole application lifecycle?


Is it worth the effort to open/close everytime needed (and maintaining state)?

2 Answers 2

1

If you use SQLiteOpenHelper, it will cache your database object meaning it will be opened only once and closed only once. You can then use getReadableDatabase() or getWriteableDatabase() wherever and whenever is convenient because you will be using the cached database.

SQLiteOpenHelper also makes it really easy to create, open, and upgrade (and with API 11, downgrade too) your database and is the Google recommended way of working with SQLite.

0
  1. Open the database once => One open/close
  2. Open the database multiple times => Multiple open/close

In 1) and 2), the memory cost is the same while the database is open. So 2) is obviously more expensive with this very reduced set of hypothesis.

1
  • 1
    but there must be some cost for the database being open the whole process cycle? Jul 26, 2011 at 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.