Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/clarification: Statement#finalize #356

Closed
Prinzhorn opened this issue Feb 28, 2020 · 5 comments
Closed

Feature/clarification: Statement#finalize #356

Prinzhorn opened this issue Feb 28, 2020 · 5 comments
Labels

Comments

@Prinzhorn
Copy link
Contributor

Prinzhorn commented Feb 28, 2020

At first I wanted to ask for a finalize method on the Statement class.

int sqlite3_finalize(sqlite3_stmt *pStmt);

https://sqlite.org/c3ref/finalize.html

But looking at the code I think this is already handled automatically? https://github.com/JoshuaWise/better-sqlite3/blob/18b957249b2891698231493f42e99a20ace5def9/src/objects/statement.lzz#L41-L45

I'm not familiar with the native side of Node at all. Do I interpret that correctly that the destructor handles that and is called when the garbage collector cleans up? So if I assign a new statement to an existing variable (and no other references exist), the old statement will automatically be finalized in SQLite? If this is correct then you can close the issue!

@JoshuaWise
Copy link
Member

JoshuaWise commented Feb 28, 2020

Yes, there's no finalize method in better-sqlite3 because memory is managed by the garbage collector, as you would expect from any regular JavaScript package. The garbage collector calls the destructors, and the destructors finalize the statement.

Also, if a database object is cleaned up by the garbage collector, it is automatically closed.

@Prinzhorn
Copy link
Contributor Author

Thank you for the amazing work you are doing.

@kjackson1998
Copy link
Contributor

@JoshuaWise Hi I spent a long time looking up how to finalize my statements. I ended up deep down here in a closed issue from 2020 to find the answer (which makes sense).

But boy would it have been helpful to have this called out in your docs on Statement, and saved me a lot of time.

@mceachen
Copy link
Member

mceachen commented Jan 1, 2025

A pull request to improve documentation would be welcome, @kjackson1998 !

@kjackson1998
Copy link
Contributor

np. #1310

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

No branches or pull requests

4 participants