# Why Go benchmarks allocate heap memory for interface values

DevFeed: [Why Go benchmarks allocate heap memory for interface values](<https://devfeed.tech/articles/a-few-bytes-here-a-few-there-pretty-soon-you-re-talking-real-memory-20836.md>)

Original publisher: [Read original article](<https://dave.cheney.net/2021/01/05/a-few-bytes-here-a-few-there-pretty-soon-youre-talking-real-memory>)

Author: Dave Cheney

Published: 2021-01-05T12:39:20Z

Content type: article

Language: en

Sources: [Dave Cheney](<https://devfeed.tech/sources/dave-cheney.md>)

Topics: [Go Language](<https://devfeed.tech/topics/go-language.md>), [Benchmark](<https://devfeed.tech/topics/benchmark.md>), [Code](<https://devfeed.tech/topics/code.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>)

Tags: [benchmark](<https://devfeed.tech/tags/benchmark.md>), [code](<https://devfeed.tech/tags/code.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [go](<https://devfeed.tech/tags/go.md>), [memory](<https://devfeed.tech/tags/memory.md>), [programming](<https://devfeed.tech/tags/programming.md>)

## AI overview

This article explains why a Go benchmark allocates heap memory when a slice is passed through an interface. It attributes the allocation to the compiler moving the slice value to the heap because it cannot prove the value does not outlive its use, and discusses allocation size classes in Go 1.16.

## Source excerpt

Today's post comes from a recent Go pop quiz. Consider this benchmark fragment. A convenience wrapper around sort.Sort(sort.StringSlice(s)), sort.Strings sorts the input in place, so it isn't expected to allocate (or at least that's what 43% of the tweeps who responded thought). However it turns out that, at least in recent versions of Go, each [...]