SQLite Forum

sqlite3_db_release_memory
Login

sqlite3_db_release_memory

(1) By anonymous on 2021-01-15 10:15:37 [link] [source]

  1. When should this API be called?
  2. Is it advisable in the sqlite3_prepare_v2() ... sqlite3_step() ... sqlite3_finalize()?
  3. If the answer to 2 is affirmative, where? Before or after sqlite3_finalize()?

(2) By Richard Hipp (drh) on 2021-01-15 12:36:49 in reply to 1 [source]

There is no requirement to ever call sqlite3_db_release_memory(). If you do not call sqlite3_db_release_memory(), all the memory held by the database connection will be freed no later than when the database connection closes, and maybe before then. No action (other than closing the database connection) is needed in order to free memory held by a database connection.

The sqlite3_db_release_memory() interface is provided as an option to applications that want to minimize their memory footprint right away. The sqlite3_db_release_memory() routine clears out caches that SQLite was holding in hopes of reusing later, in order to free up as much memory space as it can. This might reduce the memory footprint, but it does so at the cost of slowing down future operations slightly (since the cached values need to be reallocated and recomputed).