2 ms·
std::mem::forget() explicitly leaks a resource, including memory[1]. The whole point is to allow circumventing running a destructor. There's also Box::leak() to
by SAI_Peregrinus 2y ago
std::mem::forget() explicitly leaks a resource, including memory[1]. The whole point is to allow circumventing running a destructor. There's also Box::leak() to quite explicitly leak memory[2]. Handy for dynamically allocating memory that needs to live for the remainder of the program (making `'static` lifetimes at runtime).
[1] https://doc.rust-lang.org/std/mem/fn.forget.html https://doc.rust-lang.org/std/mem/fn.forget.html
[2] https://doc.rust-lang.org/std/boxed/struct.Box.html#method.leak https://doc.rust-lang.org/std/boxed/struct.Box.html#method.l...