0

I am working on a chat application and in chat we are getting lots of update from server. And we are also saving the updates into the local SQLite database file.

Can someone suggest me, after every single insertion/update, should we close the database or we should close the database when it is actually needed ?

CL.
  • 173,858
  • 17
  • 217
  • 259
iShameem
  • 101
  • 9

2 Answers2

0

Closing the connection throws away the page cache, and requires that the schema version is checked and the entire schema is re-parsed the next time it is opened.

In most apps, there are not enough database accesses so that the overhead of continually re-opening the database would actually become noticeable. But this is no reason to add useless code to your app.

Please note that the SQLiteDatabase object is reference counted. So if you are using a global open helper instance, you can keep the DB open with an extra getWritableDatabase() call, even when all your other code calls close().

CL.
  • 173,858
  • 17
  • 217
  • 259
-1

You should close the connection after each query. In .net (and in most other frameworks), SQLConnections are stored in the background anyway. It won´t hit your runtime.

Also: connection pooling is your friend.

Azeros
  • 89
  • 8
  • This question is not about .NET or "most other frameworks", but about Android and iOS. – CL. Nov 27 '16 at 12:54