Skip to content
All guides

systems

Allocation and drop

Stack (default)

p = Point { x: 1.0, y: 2.0 }

Dead at end of the block, reverse declaration order.

Heap

list = [1, 2, 3]
ages = { "Asim": 30 }

[…] and { "k": v } allocate. The compiler inserts drop at scope end. Safe code does not call free.

Defer

f = File.open("x")?
defer f.close()

Runs at scope exit, reverse order: RAII without a second language of smart pointers.

Why this is fast

No mark-and-sweep. No safepoints. Destruction is a call (often inlined) at a known program point. That is what electronics and kernel paths need: predictable release, not "soon."

Raw malloc/free pairs live in unsafe only. Wrap them in a type with a drop protocol when you can.