Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardGoslice header aliasing pitfallsSingle-choice MCQ

A function reads one element from a huge slice and stores the sub-slice in a long-lived struct. Why can this be a memory leak even though only one element is referenced?

var cache [][]byte func keepFirst(big []byte) { cache = append(cache, big[0:1]) }