Manage memory and ensure data persistence via Close()
mainBecause DuckDB runs in-process, all memory allocations occur within the host Go application. For long-running applications, you must call the appropriate Close() functions to prevent memory leaks and ensure data integrity.
Crucially, for persistent DuckDB databases, calling Close() on the database or connector is required to synchronize changes from the Write-Ahead Log (WAL) to the persistent storage. Failure to do so may result in data loss.
db, err := sql.Open("duckdb", "")
defer db.Close()
conn, err := db.Conn(context.Background())
defer conn.Close()
rows, err := conn.QueryContext(context.Background(), "SELECT 42")
rows.Close()
appender, err := duckdb.NewAppenderFromConn(conn, "", "test")
defer appender.Close()
c, err := duckdb.NewConnector("", nil)
defer c.Close()