# M0111 heap allocation (/docs/diagnostics/codes/m0111)

Heap allocations cost time in the allocator and the garbage collector; those in loops cost on every iteration.

## The mistake and the fix [#the-mistake-and-the-fix]

<div className="code-pair">

```go title="The mistake"
func newPoint() *Point {
	return &Point{1, 2} // returned: heap
}
```

```go title="Fixed"
func point() Point { // [!code highlight]
	return Point{1, 2} // a value: no allocation // [!code highlight]
}
```

</div>

## The fix [#the-fix]

Return values instead of pointers, pass buffers in, keep large arrays out of loops, or avoid interfaces on hot paths.

See also [all error codes](/docs/diagnostics/codes) and [marmot explain](/docs/commands/explain).