Freeing in an atexit()

Is there any point to freeing memory in an atexit() function?

I have a global variable that gets malloc'ed after startup. I could write an atexit() function to free it, but isn't the system going to reclaim all that memory when the program exits anyway?

Is there any benefit to being tidy and actively cleaning it up myself?


Not in C - it's like rearranging the deck chairs while the ship sinks around you.

In C++ the answer is different, because objects can delete temporary files and so forth in their destructors, so you need to make sure those get called.


释放它的一个好处是,如果你曾经做过任何内存泄漏测试,试图在流程的整个生命周期内将分配与释放进行匹配,那么不会因这种故意泄漏而导致误报。


在所有现代操作系统中,您可以放心地假定当程序退出时所有内存都将被释放。

链接地址: http://www.djcxy.com/p/19916.html

上一篇: 内存泄漏是否有可接受的限制?

下一篇: 在atexit中释放()