6.9 Comparison Summary: Rust vs. C Memory Management

FeatureC / C++ (Manual/RAII)Rust (Ownership & Borrowing)
Memory SafetyProne to leaks, dangling ptrs, double frees, use-after-free, buffer overflowsCompile-time prevention of these memory errors in safe code
Resource MgmtManual (free) or RAII (destructors)Automatic (Drop trait based on scope/ownership)
Data RacesPossible via aliased mutable pointers (even single-threaded UB), or thread concurrencyPrevented by borrow checking (&/&mut), Send/Sync traits for threads
PointersRaw pointers (*), potential null/invalid state/aliasing issuesSafe references (&/&mut), guaranteed valid/non-null; raw pointers only in unsafe
ConcurrencyRequires manual locking/synchronization, error-proneOwnership/borrowing + Send/Sync provide compile-time concurrency safety
Runtime OverheadMinimal (manual) or depends on smart pointer/RAII logicMinimal (compile-time checks, Drop calls, slice bounds checks)
FlexibilityHigh, but requires significant discipline for safetyHigh, with safety by default; unsafe provides low-level control when needed

Rust’s ownership and borrowing system provides performance and control comparable to C/C++ while eliminating many common memory safety and concurrency pitfalls at compile time. This shifts bug detection much earlier in the development cycle.