4 ms·
Don't get too comfy with Rust! Memory leaks are memory safe, so a logic error can still lead to a leak. RAII doesn't guarantee that no leaks are possible. Just
by fny 10y ago
Don't get too comfy with Rust! Memory leaks are memory safe, so a logic error can still lead to a leak. RAII doesn't guarantee that no leaks are possible.
Just take a gander at std::mem::forget[0], which is part of "safe" Rust:
> "Leaks a value: takes ownership and "forgets" about the value without running its destructor. Any resources the value manages, such as heap memory or a file handle, will linger forever in an unreachable state."
[0]: https://doc.rust-lang.org/std/mem/fn.forget.html https://doc.rust-lang.org/std/mem/fn.forget.html
- dbaupp 10y agoYou're correct but that's kind-of missing the point: I imagine the parent was trying to say you can have the deterministic management of non-memory resources like C++, without the downside of loosing memory safety. It's low-signal to say that memory leaks are possible, since, as the article in question demonstrates, it's perfectly possible to get leaks in languages like Java. On `forget`, it's equivalent to the following Python, which can be translated into pretty much any language one wants: holds_reference = [] def forget(x): global holds_references holds_reference.append(x) There are cases where one needs to think about avoiding leaks, but no more than C++.
- marcosdumay 10y ago> I imagine the parent was trying to say you can have the deterministic management of non-memory resources like C++, without the downside of loosing memory safety. At least, that's what I was talking about. But the GP has a point. It will leak other resources the same way it leaks memory. That is, it will rarely do so, but it's something you have to keep in mind.