Member-only story

Memory management in Rust — Part 1: Ownership and Moves

An introduction to memory management in Rust

Mousse Anis
5 min readJul 8, 2022

Do not worry; I am not trying to sell you the latest Titok dance routine or the benefits or inconveniences of owning a house etc. We will review the concepts of Ownership and Moves in the programing language Rust.

In one of my first articles of 2022, Why you learn Rust! I mentioned that one of the most attractive features of Rust is its Safety. We will dive into the Safety aspect of our favorite programming language and try to understand how the memory is managed.

Memory management

Programming languages are often defined by how they handle memory management.

In the perfect world, a programming language should be able to allocate memory at will, while ensuring that a pointer to an object that has been freed(dangling pointer) can not be used.

But we are not living in a perfect world, so some programming languages like Python or Java opt to delegate the responsibility of removing dangling pointers to a garbage collector; Still, others, such are C or C++, simply ( 🤣 ) leave you in charge of freeing the memory.

Rust takes a different approach by restricting how pointers are used in a program. The concept of Ownership

--

--

Mousse Anis
Mousse Anis

Written by Mousse Anis

Ex Quant, now software engineer who loves to cook. Opinions/Views are my own

Responses (1)