Curriculum Memory Ownership conventions exercise 3 · mcq
Ownership conventions
TypeScript's String.prototype.toUpperCase() returns a new
string. The Zig equivalent — toUpperCopy(a, s) — ALLOCATES
the result. Pick the right call site shape (the call AND the
caller's cleanup).
TypeScript reference
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.