3 ms·
Technically it's possible to leak a Box without using `unsafe`, since the std::mem::forget function is not marked as an unsafe function (because it itself can't
by kibwen 10y ago
Technically it's possible to leak a Box without using `unsafe`, since the std::mem::forget function is not marked as an unsafe function (because it itself can't cause memory unsafety, and because there are (incredibly convoluted) ways to create an equivalent function entirely in safe code).
However, the only reason you'd have for using std::mem::forget would be because you're doing unsafe things elsewhere in the program (as discussed at http://doc.rust-lang.org/std/mem/fn.forget.html http://doc.rust-lang.org/std/mem/fn.forget.html ), so you're correct that in practice there's almost always an `unsafe` block somewhere that's the culprit.