None
FR
Rust: Memory Management
[]
Emil Privér
When you push data to the heap, it looks for a suitable memory location to allocate and store your data, and then it gives you a reference to the memory slot where the pushed data is stored. fn main ( ) { let s1 = String :: from ( "Stack item 1" ) ; let s2 = String :: from ( "Stack item 2" ) ; let s3 = String :: from ( "Stack item 3" ) ; let s4 = String :: from ( "Stack item 4" ) ; let s5 = String :: from ( "Stack item 5" ) ; } When you invoke .clone() in Rust, it duplicates the data from the memory location you wish to clone, finds a place to allocate space, stores the cloned data in that space, and then returns a reference to the new memory location that contains the exact same data as the original.