1

I was curious what would be happen to the first heap allocated String? Is it dropped at compile time by drop call automatically and implicitly or what?

fn main() {
    let mut str1 = String::from("String1"); // I'm in the heap right?
    println!("str is: {}", str1);
    // what's gonna happen here, we don't have GC in rust, so...?
    // does compiler automatically call drop here?
    str1 = String::from("String2"); // I'm in the heap again, how the previous one get removed from heap?

    println!("str is: {}", str1);

}

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Mehdikovic
  • 51
  • 5

0 Answers0