Garbage collection automatically reclaims heap memory when no program variables refer to it. Background runtime code periodically checks those references, so developers do not explicitly deallocate each value. section 2.2
Automatic memory management trades manual cleanup for simpler allocation:
- Manual memory management requires developers to allocate the right amount and deallocate it at the right time. section 2.2
- Garbage collection removes the explicit deallocation step and reduces errors such as use-after-free. section 2.2
- Rust avoids a run-time garbage collector while still providing tools for controlling memory allocations when performance requires it. section 1.2
Explicit cleanup versus automatic cleanup
A K welcome program calls free(name) after using the input. Garbage-collected languages perform the corresponding reclamation automatically when the value is no longer referenced, while Rust handles ownership and cleanup without a run-time collector. section 2.2 section 1.2
Listing 2.6 The welcome program written with K
def welcome(name):
print('Welcome ' + name)
name = input('Please enter your name: ')
welcome(name)
free(name)
Compare the explicit free(name) call with automatic reclamation and see why manual cleanup places responsibility on the developer. section 2.2








