3 ms·
While this is a joke, it somewhat resonates with my experience of working on a huge C++ project (search engine, tens of millions of lines). Over the years I ha
by alexey-salmin 3y ago
While this is a joke, it somewhat resonates with my experience of working on a huge C++ project (search engine, tens of millions of lines).
Over the years I had been debugging multiple memory problems and only once I had found a true memory leak. It wasn't the bug I was looking for, accounting for only 8 bytes per hour and it was the easiest of all: directly discovered by valgrind.
All others were memory bloat cases: memory reachable but not used. Like forgetting some small per-request descriptor in some auxiliary hashmap in one of the code pathways. Reproducing and debugging was pain because it required running a loaded backend for days under a profiler, before the bloated part becomes visible.
Funny thing is that while C++ is notorious for memory leaks this particular kind of problem is possible in any language that allows a global mutable state (so all the practical ones). From experience it seems that true leaks are unlikely in a reasonably-good C++ code. Just never mix business logic with memory management and you're good to go.