While we have the stack and heap, Rust also has another type of memory allocation, that is, statically allocated memory. This is not allocated at runtime, but moves into memory with the program's code before the program is run.
The likes of static
and const
variables are good examples of static allocations.
Static memory allocation has the same lifetime as that of the application.
If you're used to any of the .NET languages, you'll be more than accustomed to the garbage collector (GC). Essentially, when all references to an object have gone out of scope, the object's heap allocation is freed up by the garbage collector. The garbage collector comes around every once in a while, basically checks through the whole space of allocated memory to see if something isn't used anymore, and removes such content from memory; in other words, the garbage left behind by a deallocated pointer is collected and removed.
Rust has a primitive garbage...