sync.Pool: a cache of temporary objects for reuse
Answer: A Pool is a set of temporary objects that may be individually saved and retrieved. Get removes one item. Put adds one. Stored items may be removed at any time. It is safe for use by multiple goroutines, and must not be copied after first use.
Get, Put, and New
A Pool is a set of temporary objects that may be individually saved and retrieved.
Get selects an arbitrary item, removes it from the Pool, and returns it.
Get may treat the pool as empty.
Callers should not assume a relation between Put values and later Get values.
When Get would have returned nil and New is set, Get calls New and returns that result.
New optionally specifies a function to generate a value when Get would otherwise return nil.
Put adds x to the pool.
When a Pool helps, and when it does not
Any item stored in the Pool may be removed automatically at any time without notification.
Several goroutines may use the same Pool at the same time.
A Pool caches allocated but unused items for later reuse. That relieves pressure on the garbage collector.
That makes thread-safe free lists easy to build, but not every free list should use a Pool.
The fmt package is the usual example: it keeps a store of temporary output buffers that grows and shrinks with load.
Do not copy a Pool after you first use it.
See also
Claims
- id: C1 claim: A Pool holds temporary objects that can be saved and retrieved. source: S1 evidence: "temporary objects that may be individually saved"
- id: C2 claim: Get removes an arbitrary item and returns it. source: S1 evidence: "selects an arbitrary item from the"
- id: C3 claim: Get may ignore the pool and treat it as empty. source: S1 evidence: "ignore the pool and treat it as empty"
- id: C4 claim: Put adds a value to the pool. source: S1 evidence: "Put adds x to the pool"
- id: C5 claim: Stored items may be removed automatically at any time. source: S2 evidence: "removed automatically at any time without"
- id: C6 claim: A Pool must not be copied after first use. source: S2 evidence: "must not be copied after first use"
Sources
- [S1] sync package reference. Go. https://pkg.go.dev/sync . License: BSD-3-Clause. Accessed 2026-11-23.
- [S2] sync/pool.go source. Go. https://go.dev/src/sync/pool.go . License: BSD-3-Clause. Accessed 2026-11-23.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go, sync package reference; Go, sync/pool.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Go, sync package reference; Go, sync/pool.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.
Cite this
iinventedlight. 2026. "sync.Pool: a cache of temporary objects for reuse." iinventedlight Library, iil:note:4chpxmd3, version of 2026-11-23. https://iinventedlight.com/library/notes/go-sync-pool/. License: CC-BY-4.0.
@misc{iil_note_4chpxmd3,
author = {{iinventedlight}},
title = {{sync.Pool: a cache of temporary objects for reuse}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-23},
url = {https://iinventedlight.com/library/notes/go-sync-pool/},
note = {Permanent ID iil:note:4chpxmd3. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- go-sync-pool.schema.json (schema; CC-BY-4.0)
- go-sync-pool.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-sync-pool.md.