0

While I was looking into documentation of Rust, there is a statement in static.

Static items do not call drop at the end of the program.

The way that I understand is if I make static FOO: Vec<u8> = vec![1, 2, 3]; then it is not going to free underlying memory.

Could you please explain the reason of this.

marknikky
  • 101
  • 1
  • 5
  • 3
    " it is not going to free underlying memory." That's not really a problem as the whole program memory is freed anyway, is it ? – Denys Séguret May 17 '21 at 14:09
  • 1
    As the question is about the reason, I think it's clearly explained in this answer: https://stackoverflow.com/questions/58141569/is-there-a-way-to-drop-a-static-lifetime-object-in-rust – Denys Séguret May 17 '21 at 14:19
  • 3
    It may be noteworthy that you actually *can't* create a (non-empty) `static` `Vec` since heap allocation can't be done in a `const fn`. – trent May 17 '21 at 14:27

0 Answers0