4 ms·
Just because memory can be freed doesn't mean it has to; the programmers can choose not to. The mode of not freeing has been explored in programs that are shor
by kazinator 10y ago
Just because memory can be freed doesn't mean it has to; the programmers can choose not to.
The mode of not freeing has been explored in programs that are short-lived and run on top of an OS that reliably cleans up memory. For instance, system utilities and compilers and such.
Got a C program that crashes due to premature allocation, according to Valgrind, and it is hard to figure out why? It it just a short-lived utility that does some job and exits? Then just #define free(p) ((void) 0) and rebuild.
- foota 10y agoGood luck explaining that one in the code review :p
- PeCaN 10y agoOr because it's considerably faster—if you don't have to deallocate, you can just reserve a bunch of pages on startup and use a stupid simple bump allocator. Actually, D's compiler more or less works this way: http://www.drdobbs.com/cpp/increasing-compiler-speed-by-over-75/240158941 http://www.drdobbs.com/cpp/increasing-compiler-speed-by-over...
- kazinator 10y agoI have seen a program, which meticulously freed everything on shutdown, take over a minute to actually do so under a large and complex test case involving lots of data. In production use, this would be a complete waste of CPU cycles.
- ksherlock 10y agoOver a minute? At least it didn't take a few days... http://lists.gnu.org/archive/html/coreutils/2014-08/msg00012.html http://lists.gnu.org/archive/html/coreutils/2014-08/msg00012... https://news.ycombinator.com/item?id=8305283 https://news.ycombinator.com/item?id=8305283
- lloeki 10y ago> The mode of not freeing has been explored in programs that are short-lived [fork, allocate, exit] is a very valid and robust pattern leveraging the OS as a garbage collector. This kind of pattern reminds me of crash-as-an-operation-mode software.
- jandrese 10y agoThat's a fine solution, but you're going to cause some weenie manager's head to explode. Also, some hapless intern is going to copy a chunk of code out of your project in their new project and then give you hell because their program leaks memory like crazy. Also, some mid level manager is going to decide that all code must be run through static analysis and come out cleanly and you're going to have a bad day.