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
pull/1160/head
Jack Christensen 2021-12-29 17:25:43 -06:00 committed by Jack Christensen
parent 1e565b0d44
commit b6b24f9e8a
1 changed files with 3 additions and 9 deletions

12
conn.go
View File

@ -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
@ -513,12 +512,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