Skip to content

non-pointer-sync-pool-value

Detect sync.Pool values that allocate while being stored.

Updated View as Markdown

Default severity: warning

sync.Pool.Put accepts an interface. Storing a concrete non-pointer value requires boxing it on the heap, adding the allocation the pool is intended to avoid. Slices are also boxed because the slice header itself is a value.

Store a pointer to the reusable value instead. Pointer-like maps, channels, functions, interfaces, and unsafe pointers are accepted.

Bad

buffer := make([]byte, 0, 4096); pool.Put(buffer)

Good

buffer := make([]byte, 0, 4096); pool.Put(&buffer)
Navigation

Type to search…

↑↓ navigate↵ selectEsc close