Skip to content

Commit e621d88

Browse files
committed
doc: update garbage collection description
which hasn't been updated since 2010 [skip ci]
1 parent 81ea485 commit e621d88

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

CONTRIBUTING.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,15 @@ please look there for additional information.
1616

1717
All statements keep pointers back to their respective database connections.
1818
The `@connection` instance variable on the `Statement` handle keeps the database
19-
connection alive. Memory allocated for a statement handler will be freed in
20-
two cases:
19+
connection alive.
2120

22-
1. `#close` is called on the statement
23-
2. The `SQLite3::Database` object gets garbage collected
24-
25-
We can't free the memory for the statement in the garbage collection function
26-
for the statement handler. The reason is because there exists a race
27-
condition. We cannot guarantee the order in which objects will be garbage
28-
collected. So, it is possible that a connection and a statement are up for
29-
garbage collection. If the database connection were to be free'd before the
30-
statement, then boom. Instead we'll be conservative and free unclosed
31-
statements when the connection is terminated.
21+
We use `sqlite3_close_v2` in `Database#close` since v2.1.0 which defers _actually_ closing the
22+
connection and freeing the underlying memory until all open statments are closed; though the
23+
`Database` object will immediately behave as though it's been fully closed. If a Database is not
24+
explicitly closed, it will be closed when it is GCed.
3225

26+
`Statement#close` finalizes the underlying statement. If a Statement is not explicitly closed, it
27+
will be closed/finalized when it is GCed.
3328

3429

3530
## Building gems

0 commit comments

Comments
 (0)