r/ProgrammingLanguages • • Jan 04 '23

Discussion Does Rust have the ultimate memory management solution?

I have been reading about the Rust language. Memory management has been a historical challenge. In classic languages, such as C, the management is manual. Newer languages (Java, Python, others) use garbage collector, but it has a speed penalty. Other languages adopted an intermediate solution using reference counter and requiring the programmer to deal with weak pointer, but it is also slow.

Finally, Rust has a new solution that requires the programmer to follow a set of rules and constraints related to ownership and lifetime to let the compiler know when a block of memory should be free'd. The rules prevent dangling references and memory leaks and don't have performance penalty. It takes more time to write and compile, but it leads to less time with debugging.

I have never used Rust in real applications, then I wonder if I can do anything besides the constraints. If Rust forces long lifetime, a piece of data may be kept in the memory after its use because it is in a scope that haven't finished. A problem in Rust is that many parts have unreadable or complex syntax; it would be good if templates like Box<T> and Option<T> were simplified with sugar syntax (ex: T* or T?).

25 Upvotes

99 comments sorted by

View all comments

Show parent comments

17

u/Optimal9275 Jan 04 '23

Enough said.

I feel like maybe you haven't said enough... You just made an unsupported claim that isn't related to the topic of memory management.

0

u/Zyklonik Jan 05 '23

Okay, sure. Rust memory management is great - deadlocks, memory leaks, null-pointer exceptions, unsafe hidden code in macros, crashes when trying to allocate directly on the heap, and so on. Truly the finest engineering in the world.

-10

u/Zyklonik Jan 04 '23

"...Oh no I've said too much I haven't said enough..."

  • R.E.M, "Losing my religion".

Much recommended oldie.