typeover
curriculum

Curriculum Memory Ownership conventions exercise 5 · fill-word

Ownership conventions

Fill the missing cleanup keyword for the CALLER who took ownership of an allocation. The keyword runs unconditionally when the block exits.

TypeScript reference
Fill the blanks →

About this theme

Zig has no borrow checker — ownership is convention, not enforcement. The rule that makes manual memory livable: whoever calls init is responsible for calling deinit. A function that allocates and returns ownership uses errdefer to clean up on failure; the caller then defers the deinit. A function that borrows takes a slice or pointer and never frees. Once these conventions become reflex, manual memory feels almost as easy as garbage collection — minus the runtime cost.