From e3703b7ebc32b6099acdf82a8b12e8ac68625c5c Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Wed, 29 Dec 2021 17:25:43 -0600 Subject: [PATCH] Allocate connRows on demand instead of preallocating in bulk The 64 element preallocatedRows may be pinning memory from previous queries. See https://github.com/jackc/pgx/issues/1127 --- conn.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/conn.go b/conn.go index 102158ab..6de0cda4 100644 --- a/conn.go +++ b/conn.go @@ -73,9 +73,8 @@ type Conn struct { connInfo *pgtype.ConnInfo - wbuf []byte - preallocatedRows []connRows - eqb extendedQueryBuilder + wbuf []byte + eqb extendedQueryBuilder } // Identifier a PostgreSQL identifier or name. Identifiers can be composed of @@ -537,12 +536,7 @@ func (c *Conn) execPrepared(ctx context.Context, sd *pgconn.StatementDescription } func (c *Conn) getRows(ctx context.Context, sql string, args []interface{}) *connRows { - if len(c.preallocatedRows) == 0 { - c.preallocatedRows = make([]connRows, 64) - } - - r := &c.preallocatedRows[len(c.preallocatedRows)-1] - c.preallocatedRows = c.preallocatedRows[0 : len(c.preallocatedRows)-1] + r := &connRows{} r.ctx = ctx r.logger = c