Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to "close" a connection in SQLite.swift?

Tags:

sqlite.swift

Not sure about whether I should and how to close a Connection in SQLite.swift. Will it cause thread/memory leak?

like image 269
henrichen Avatar asked Nov 10 '22 00:11

henrichen


1 Answers

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.

like image 163
Eric Yuan Avatar answered Jan 04 '23 01:01

Eric Yuan