Standard library / sync
sync.Pool
Temporary object reuse, not a guaranteed cache or resource owner. Items may disappear at any time. Do not copy after use. Expected stdout: '0\n'.
Formal Syntax & Structure
go syntaxgo
type Pool struct {
New func() any}Working Example
Example Snippetgo
package main
import ( "fmt" "sync")
func main() { p := sync.Pool{New: func() any { return new(int) }} v := p.Get().(*int) fmt.Println(*v) p.Put(v)}