3 ms·
You're conflating memory safety and memory usage/management. Safe Rust prevents you from addressing or accessing arbitrary memory, null pointer dereferencing, a
by Someone1234 2y ago
You're conflating memory safety and memory usage/management. Safe Rust prevents you from addressing or accessing arbitrary memory, null pointer dereferencing, and buffer overflows, while remaining performant relative to other memory safe languages (e.g. Java, Python, Go, Ada, etc). In particular, it doesn't have a Garbage Collector.
There is no actual difference between a memory "leak" and intentionally allocated memory except the INTENT of the developer. It is important for good language design to avoid accidental memory leaks via well-designed constructs. Ultimately there will always need to be a mechanism for a developer to create a block of allocated memory and free it only on their schedule.
Rust's language design does make it harder to leak memory, and well written Rust would rarely do so. However, if Rust made arbitrary allocations impossible, certain use cases would also be nearly impossible and performance for others would suffer greatly (e.g. allocating a buffer ahead of time, for the lifetime of a worker). It is a balance, at some point you have to trust the developer to make decisions.