Hacker News new | ask | show | jobs
by nayuki 2535 days 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

1 comments

`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.