4 ms·
> I think it's possible to leak memory if you are sufficiently clever and doing really weird stuff Note that Rust provides an easy way to intentionally leak me
by nayuki 7y ago
> I think it's possible to leak memory if you are sufficiently clever and doing really weird stuff
Note that Rust provides an easy way to intentionally leak memory, unlike many other languages: https://doc.rust-lang.org/std/mem/fn.forget.html https://doc.rust-lang.org/std/mem/fn.forget.html
- pornel 7y ago`mem::forget()` only prevents destructors from running, which leaks data managed by the destructor as a side effect, but it gives no guarantees about not freeing the object passed to it (e.g. if you call it on a stack-allocated object, it can't leak it). `Box::leak()` leaks memory.