Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix args memory leak in rows.Close() #2269

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hrubymar10
Copy link

Hello,
I have found the memory leak in rows.Close() method. Please check it out.

The code for reproduction is available here: https://github.com/hrubymar10/pgx-memory-leak-test/tree/master

heap pprof before fix:
Screenshot 2025-03-04 at 11 28 20

heap pprof after fix:
Screenshot 2025-03-04 at 11 36 50

pprof files:
heap.pb.zip
heap_fixed.pb.zip

@jackc
Copy link
Owner

jackc commented Mar 4, 2025

If setting rows.args to nil allows it to be GCed, then that implies that rows cannot be GCed for some reason. That would seem to be the ultimate issue.

It looks like the preallocated buffer of poolRows in pgxpool.connResource. That saves a alloc per query, but it pins the underlying row until the preallocated buffer is GCed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants