Standard library / sync

sync.Pool.Put()

Offer an object for optional reuse; nil is ignored. Do not use the object after returning it without reacquiring ownership. Expected stdout: '0\n'.

Formal Syntax & Structure

go syntaxgo
func (p *Pool) Put(x any)

Parameters & Attributes

NameTypeDescription
xanyObject to make available for optional reuse.

Working Example

Example Snippetgo
package main
import (  "fmt"  "sync")
func main() {  p := sync.Pool{New: func() any { return new(int) }}  v := p.Get().(*int)  *v = 0  p.Put(v)  fmt.Println(*p.Get().(*int))}
Go Reference