From the course: Rust Essential Training

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Ownership

Ownership - Rust Tutorial

From the course: Rust Essential Training

Start my 1-month free trial

Ownership

- [Instructor] One of the advantages of using the heap to store data is that it's significantly bigger than the stack but it's not infinitely big. If we keep adding data to the heap without removing anything, we'll eventually run out of space and memory. So, we'll need to free up blocks of allocated memory, after they're no longer needed by the program. This task isn't unique to Rust and there are a few common approaches that other programming languages use for memory management. One traditional approach is to make the programmer responsible for explicitly allocating and de allocating memory in their code. For example, in C and C++, a programmer calls the memory allocation function named malloc, to request a block a memory of a certain size. And then when they're done using it, they can call the free function to release that memory so it can be used for something else. This approach gives the programmer a lot of control,…

Contents