I understand Rust doesn\'t have a garbage collector and am wondering how memory is freed up when a binding goes out of scope.
So in this example, I understand that Rust
With a language where you must manually manage memory, the distinction between the stack and the heap becomes critical. Every time you call a function, enough space is allocated on the stack for all variables contained within the scope of that function. When the function returns, the stack frame associated with that function is "popped" off the stack, and the memory is freed for future use.
From a practical standpoint, this inadvertent memory cleaning is used as a means of automatic memory storage that will be cleared at the end of the function's scope.
There is more information available here: https://doc.rust-lang.org/book/the-stack-and-the-heap.html