I think the bigger point is, this is a memory bug. This is the kind of issue Rust and other memory safe languages can almost entirely avoid. It's the most common flaw in programs, and any language that has those issues is imo fair to criticize given how commonly these issues are found, happen, and long they exist for. Not to mention the most complicated types of bugs to avoid in manually managed systems.
Swapping isn't easy, cheap or even possible but it's pretty clear to me that the future should be built on memory safe languages.
I am a Rust fanatic though, so I am heavily biased.
PHP, Java, JavaScript etc. are memory safe languages. They are implanted implemented* using unsafe languages, though. So is Rust (LLVM and unsafe internals).
*Damn auto-correct and needing glasses when typing on the phone.
Just dont let fanaticism blind you. Had rust dev team refuse for weeks to acknowledge a memory leak in prod no matter how much proof. Basically took the fix PR WITH tests to get them to acknowledge it. especially when using 3rd party libs that use unsafe etc
I hate rust. Unfortunately I'm forced to use it at work.
I found a fun memory leak just this past week in the rust program I'm working on. It's largely not-my-code and I've been slowly fixing and rewriting it.
Rust uses glibc under the hood. When multi-threaded Rust code rapidly creates and deletes vectors, glibc hoards that freed memory in internal pools (like thread caches and arenas) rather than returning it to the Linux kernel, intending to speed up future allocations.
However, if even a single tiny, active piece of memory sits at the top of an arena, it acts as a deadbolt, trapping all the empty deleted space beneath it and causing the application's memory usage to steadily balloon over time. So every vector create and delete was causing new arenas to be allocated, while old ones were never deleted.
Under the hood, rust loves creating and allocating new vectors on the heap instead of reusing anything. C++ will often just pass around the same heap pointer for reuse. This can cause more heap fragmentation in rust vs c++. In testing with identical code blocks that rapidly create and destroy large standard vectors (std::vec and std::vector), the rust code will leak while the c++ code does not. It's frustrating.
We were leaking around 64 MB/s. I had to manually garbage collect and trim this nonsense. I also hoisted and reused the vectors, so they aren't constantly being created and destroyed and fragmenting the heap.
I'm not saying c++ is perfect and memory safe, but I've personally had more weird memory management issues and leaks with rust than I have with c++.
Edit: I also hate how many things that are standard in c++ aren't standard in rust and require using some third-party crate. With all of the supply chain attacks going on (npm, pypi, etc), it's only a matter of time before rust crates get hit. It's just a larger threat surface.
I don't worry about c++'s std:: stealing credentials and git keys, but who knows if joe blow's rust rewrite has been compromised recently.
I mean, not if your program is required to run in constant memory they're not. Or in bounded memory without swap/overcommit, e.g. running on bare metal on a microcontroller.
(Or, just to make up a scenario, if there's a certain system configured such that the OOM killer is free to choose a process to kill at random [i.e. the default OOM-killer policy]; and there's also some process on that system responsible for either your application- or machine-level security; and whatever layer of protection that process adds is simply bypassed if that process dies...)
IMO, it's not too difficult to add new features in newer languages through bindings and you can gradually depricate old code. In my experience, getting management on board is a lot harder than actually switching.
I'm a rust dev, in practice, unsafe basically never causes vulnerabilities because it's contained, encapsulated behind safe api and there are like 20 different tools/systems in place to protect against vulnerabilities. cargo-geiger, cargo-audit, MIRI, fuzzing, multiple sanitizers. And then rustc has its own safety protocols like killing itself when an invariant fails (although that one is rarely used)
Generating and running assembly is inherently memory-unsafe. It's silly to criticize the core libraries for the possibility of memory-unsafe code when you're still trusting the entire compiler, made by the same people, to only produce memory-safe code. Those libraries are practically part of the compilation logic.
View all comments
15
u/Thomasedv Oct 22 '26
I think the bigger point is, this is a memory bug. This is the kind of issue Rust and other memory safe languages can almost entirely avoid. It's the most common flaw in programs, and any language that has those issues is imo fair to criticize given how commonly these issues are found, happen, and long they exist for. Not to mention the most complicated types of bugs to avoid in manually managed systems.
Swapping isn't easy, cheap or even possible but it's pretty clear to me that the future should be built on memory safe languages.
I am a Rust fanatic though, so I am heavily biased.