"If a variable owns a box, when Rust deallocates the variable's frame, then Rust deallocates the box's heap memory"
Who deallocates the heap memory, lets say, when there is no variable like "full" to receive the return value of "add_suffix" function, hence there is no one owning the heap data ?
the return value has a temporary scope, which, in this case, ends at the end of the function call statement. when the temporary value is dropped, the memory is deallocated.
... the temporary scope of an expression is the smallest scope that contains the expression ...
Tangential to your question, but it returns the same string. Note how String::push_str takes a &mut reference.
pub fn push_str(&mut self, string: &str)
Appends a given string slice onto the end of this String.
So,
// vvvvvv Takes `String` by value
fn add_suffix(mut name: String) -> String {
// Mutates it
name.push_str(" Jr.");
// Returns the *same* `String` by value
// (OK the `push_str` may have involved a reallocation, but conceptually)
name
}