A heap is dynamically managed memory for data whose size is unknown before execution or exceeds practical stack limits. Arrays and strings commonly use heap memory. section 2.2
Heap memory differs from stack memory in several practical ways:
- Supports much larger allocations, limited mainly by the computer’s available memory rather than a small stack limit. section 2.2
- Requires allocation to reserve an area and deallocation to make unused memory available again. section 2.2
- Uses Rust’s term dropping for the cleanup process, while deallocation remains the generic term. section 2.2
Welcoming a visitor
A program allocates enough memory for a visitor’s name, prints “Welcome {name},” and eventually releases that memory for reuse. Manual cleanup can be placed after the function call or inside the function, as shown by the contrasting welcome examples. section 2.2






