When drop is called for a mut String variable?


#1
       fn foo() {
             let mut s = String::from("a string on the heap");
             s = String::("another string on the heap"); // new allocation 
       } // when code reaches here drop is called

When code reaches } drop is called, deallocation occurs for the string “another string on the heap”. The first string how is it deallocated???


#2

At the time where s is assigned. The old value is dropped before the new one takes its place.


#3

Thanks a lot! This is reasonable.