Skip to content

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

Closed

Description

@MarieJC

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

Activity

  1. quinnj commented on Apr 14, 2022

    @quinnj
    Member

    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.

  2. MarieJC commented on Apr 14, 2022

    @MarieJC
    Author

    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.

  3. quinnj commented on Sep 30, 2026

    @quinnj
    Member

    The docs now say this plainly: a finalizer eventually closes an unreachable SQLite.DB, but its timing isn't guaranteed. For deterministic cleanup, call close(db) (or DBInterface.close!(db)), ideally in try/finally (#359). Starting with the next release, close(db) also finishes any statements that were abandoned but not yet garbage-collected (#362), so nothing stays locked or commits later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions