Chapter 06Data Structure InternalsPaid chapter

Slices: Growth, Aliasing, and Memory Retention

Explain slice sharing, retained backing storage, and append growth, and choose when to copy.

Launch paywall

This chapter is part of the paid launch. The preview stays visible so readers can evaluate the exact scope before buying.

Included in

Core and Complete. Complete also includes the practical exam and free Go-version updates.

Preview

What this chapter teaches

Common belief

A sub-slice is a cheap, independent view of part of an array. Slicing copies nothing, so it's free and safe.

What actually happens

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.

Mechanisms covered
A full slice expression constrains append capacity but does not detach or release the backing array.
Copying retained bytes can detach ownership; preallocation trades growth work against reserved memory.
experimenttracebench
One-time purchase

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.

Core
$49

Full course access with the complete mechanics curriculum.

All paid chapters unlocked
One-time purchase
Perfect if you want the material only
Complete
$79
Best value

Best-value launch option with the exam and free Go-version course updates.

Everything in Core
Black Belt practical exam
Free Go-version updates

No subscription or account required. Access is tied to the email entered at Stripe Checkout and can be restored by email.

Free chapter
Escape Analysis: The Compiler's Fragile Decision
Distinguish escape diagnostics from measured allocations and explain the role of lifetime and call-site visibility.
Free chapter
Maps: Swiss Tables, Growth, and Permanent Memory
Distinguish map table capacity from referenced payloads and inspect clearing and growth on Go 1.25.