When to open and close a connection when using sqlite with a singleton pattern

I am developing an application for IPhone and am using sqlite to connect to db. I am trying to use a singleton pattern to connect to db and receive data.

I would like to know which one is best to support, should I keep the connection open until the application closes, or open and close the connection for every call I make?

+4
source share
1 answer

SQLite must reanalyze the database schema each time a new connection is created. This can take a long time. The remaining link also opens up SQLite's ability to cache data. Since you receive ACID transactions without even closing the connection, there is no reason to close it. So, keep the SQLite connection open until the application is closed.

+6
source

Source: https://habr.com/ru/post/1336779/


All Articles