Curriculum Memory Ownership conventions exercise 1 · mcq
Ownership conventions
TypeScript's garbage collector hides ownership. Zig surfaces it via convention. Pick the right responsibility for a function that ALLOCATES a buffer and RETURNS it to the caller.
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.