Not sure about whether I should and how to close a Connection in SQLite.swift. Will it cause thread/memory leak?
Normally the database is closed when the Connection
variable is out of its using scope and reclaimed by the trash-collecting system (in the deinit
function). But sometimes it is one of your class's attributes, so you might want to close it manually in the middle of some functions. Hence this code works:
sqlite3_close(db.handle)
where db
has the type of Connection
. You can then override the database file or delete it, no warnings will be raised.
Anyways, I highly recommend you design your code in a cautious way to let the system frees the handle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With