exit() Rather Than free()
December 10, 2009 Leave a comment
I have to admit that I had a bit of a reaction to this post, apologies for quoting more than 50% of the post here but here goes:
See, developers are perfectionists, and their perfectionism also includes the crazy idea that all memory has to be deallocated at server shutdown, as otherwise Valgrind and other tools will complain that someone leaked memory. Developers will write expensive code in shutdown routines that will traverse every memory structure and deallocate/free() it.
Now, guess what would happen if they wouldn’t write all this expensive memory deallocation code.
OS would do it for them, much much much faster, without blocking the shutdown for minutes or using excessive amounts of CPU. \o/
I am really uncomfortable with the approach of using free() for memory cleanup for the obvious reason that it is usually much, much cheaper to keep a process running than to shut it down and restart it on a regular basis. The other reason is that to rely on free() for memory cleanup is just poor hygiene.
Reminds me of the days of SunOS where common wisdom said that restarting a server once a week was a good idea to keep the memory leaks in check.