2.13 Memory Safety and Ownership
Rust’s ownership and borrowing rules ensure safety without requiring a garbage collector:
- Ownership: Each value has a single owner.
- Borrowing: References let you read or modify values without taking ownership.
- No Null: Rust does not allow “null” references; optional data is handled via
Option<T>
.
2.13.1 Comparison with C
In C, manual allocation and deallocation (malloc
, free
) can cause memory leaks or invalid pointer references. Rust prevents many of these issues through compile-time checks enforced by its ownership model.