Skip to content

Commit 07871c0

Browse files
committed
Zero internal baseRows references to allow GC earlier
See #2269
1 parent 777e7e5 commit 07871c0

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

rows.go

+11
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,17 @@ func (rows *baseRows) Close() {
188188
} else if rows.queryTracer != nil {
189189
rows.queryTracer.TraceQueryEnd(rows.ctx, rows.conn, TraceQueryEndData{rows.commandTag, rows.err})
190190
}
191+
192+
// Zero references to other memory allocations. This allows them to be GC'd even when the Rows still referenced. In
193+
// particular, when using pgxpool GC could be delayed as pgxpool.poolRows are allocated in large slices.
194+
//
195+
// https://github.com/jackc/pgx/pull/2269
196+
rows.values = nil
197+
rows.scanPlans = nil
198+
rows.scanTypes = nil
199+
rows.ctx = nil
200+
rows.sql = ""
201+
rows.args = nil
191202
}
192203

193204
func (rows *baseRows) CommandTag() pgconn.CommandTag {

0 commit comments

Comments
 (0)