Slices: Growth, Aliasing, and Memory Retention
Explain slice sharing, retained backing storage, and append growth, and choose when to copy.
This chapter is part of the paid launch. The preview stays visible so readers can evaluate the exact scope before buying.
Core and Complete. Complete also includes the practical exam and free Go-version updates.
What this chapter teaches
A sub-slice is a cheap, independent view of part of an array. Slicing copies nothing, so it's free and safe.
copies nothing" is exactly the problem. A sub-slice shares the original's backing array. append into spare capacity writes through that shared array, corrupting other slices that point at it. And because the whole backing array stays reachable as long as any sub-slice references one byte of it, a tiny sub-slice can keep a huge allocation alive — a memory leak with no leaked pointer in sight. The slice header is three words; the data is shared.
Unlock Chapter 06 and the rest of the course.
Core unlocks every paid chapter and lab. Complete also includes the practical exam and future Go-version updates.
Full course access with the complete mechanics curriculum.
Best-value launch option with the exam and free Go-version course updates.
No subscription or account required. Access is tied to the email entered at Stripe Checkout and can be restored by email.