Earlier quoted context omitted.
Not in the sense I meant to make the comparison - Zig doesn't even pretend to do memory safety - if you don't free something manually it won't get freed - this is way worse level of safety than even what C++ with unique_ptr. In contrast if Rust only ensured that a reference doesn't outlive the scope it's valid in (allocated and cleaned up via RAII), a lot of problems with Rust would go away, like you could have 2 mut…
> Zig doesn't even pretend to do memory safety This is simply untrue. Zig offers the same spatial memory safety as Rust does, and that is the kind of memory safety that prevents more dangerous vulnerabilities [1] than the kind Rust offers and Zig doesn't (temporal memory safety). > if you don't free something manually it won't get freed Rust also isn't free of memory leaks, and doesn't even pretend to guarantee that…
Zig doesn't have the memory safety mechanisms of C++ level shared_ptr/unique_ptr.
It's essentially C's malloc/free with the added safety of defer (or possibly arenas), but making sure that the program doesn't leak memory (or have use-after-free bugs) falls on the programmer.
And memory leaks are a much lesser problem, as they usually lead to crashes in OoM situation, than gaining access to random blocks of memory.
Besides, the way you trigger memory leaks in Rust/C++ is with circular references, which are much harder to create than just missing a free() somewhere.
If you have memory that's not tied to a function scope's lifetime in Zig (or the scope of an allocator), then you're essentially have to go by C rules