Description
Hi,
We're facing a significant memory leak in our product (v1.14, running on Linux) and have been actively investigating its cause.
Our pprof heap profile points to the SQLiteRows.Columns function and related calls on SQLiteStmt and SQLiteConn as the source. Based on the code:
- SQLiteRows holds a reference to SQLiteStmt, which in turn references SQLiteConn.
- Our analysis of the database/sql package suggests that the SQLiteRows instance is the only Go object maintaining a reference to the memory allocated by Columns() in our specific use case.
Therefore, while pprof indicates a leak of SQLiteRows references, our code inspection and usage patterns don't immediately reveal any obvious leaks of these objects. We've confirmed that the memory usage increases steadily over time, not in sudden spikes, and we've ruled out goroutine leaks as a contributing factor.
Interestingly, a core dump analyzed with goref shows only around 130MB of in-use data, which doesn't seem related to sqlite3. This contrasts sharply with the heap profile, which indicates several gigabytes of Go-allocated memory. This discrepancy leads us to suspect that C allocations might be contributing to the observed Go heap growth (potentially making the heap profile appear inaccurate in this specific scenario).
We've considered potential issues with Go runtime or finalizer changes, but your current implementation appears correct. We also tested with the latest Go 1.23, but the problem persists.
We are currently investigating a potentially relevant issue discussed in this PR on a fork, which might offer an explanation for this behavior.
Unfortunately, we haven't been able to reproduce the issue in a controlled environment yet.
Any guidance or insights you could provide on this investigation would be greatly appreciated.
Thank you.
