Rust's Ownership model for JavaScript developers | JavaScript for Line of Business Applications | Scoop.it

Rust is an exciting new system programming language by Mozilla. In this post we explore Rust's concept of ownership that enables the language to achieve 100 % memory safety without garbage collection.


Most languages (JavaScript included) use a garbage collector to ensure memory safety.
Well then, what’s the job of a garbage collector anyway? Basically it frees up memory that isn’t used anymore, that is, memory that nothing in the program points to anymore. Traditionally languages that are not memory safe such as C and C++ delegate that work to the developer. As we all know humans aren’t free from failure and so here are some examples of problems that may arise with manual memory management
access to memory that has already been freed
trying to free memory that has already been freed (double free)
not freeing memory at all that rather should have been freed (memory leak)

Rust doesn’t use a garbage collector while still being 100 % memory safe. So how does that work and how does it affect the way we write our code?