SQLite.jl icon indicating copy to clipboard operation
SQLite.jl copied to clipboard

Explicit GC.gc() needed for SQLite.DB to become really out of scope.

Open MarieJC opened this issue 3 years ago • 2 comments

Otherwise at the end of program execution sqlite database remains in use by Julia REPL. And according to the doc: "The SQLite.DB will be automatically closed/shutdown when it goes out of scope (i.e. the end of the Julia session, end of a function call wherein it was created, etc" - turns out not true! Link to JuliaLang discussion of the problem: https://discourse.julialang.org/t/sqlite-database-remains-in-use-by-julia-repl/77194

MarieJC avatar Feb 28 '22 16:02 MarieJC

Hi @MarieJC, thanks for opening an issue! Yeah, this is somewhat a general Julia "destructor" problem as we're relying on the finalizer functionality in Julia, which allows you to register a function that runs when an object is garbage collected. But the problem is, as you noted, it's not well-defined when objects actually get garbage-collected!

Do note that you can always call close(db) or more generally DBInterface.close!(db) to force a database connection to be closed, which we should probably highlight in the docs as the proper way to manage the lifetime resource of your sqlite database connection.

quinnj avatar Apr 14 '22 04:04 quinnj

Thank you for your response! Yes, DBInterface.close!(db) works. But in my particular exercise the code operating on a db isspread between diff functions - so it is tricky to close the db at the very end. This is not a priority though!!! We were just testing out similar functionality in several languages, including Julia.

MarieJC avatar Apr 14 '22 10:04 MarieJC