Is it possible to cause a memory leak in Rust?
Yes, leaking memory in Rust is as easy as calling thestd::mem::forget
function.Memory leak can happens also if you create a cycle of shared references:
Memory could also be leaked by
std::rc::Rc
or Arc
, through reference cycles.All those examples show that a memory leak does not offend the memory safety guaranteed by Rust. However, it is safe to assume that in Rust, you do not have any memory leak, unless you do a very specific thing.