struct Item {
name: String,
}
impl Item {
fn new(x: &str) -> Item {
Item { name: String::from(x) }
}
fn change_name(&mut self, x: &str) {
self.name = String::from(x);
}
}
fn main() {
let mut item1 = Item::new("Foo");
item1.change_name("Bar");
}
When I call item1.change_name()
, what will happen to the String("Foo")
assigned to the name
previously. When will drop()
be called on the String("Foo")
? Will this leak memory?