Should I free allocated memory on abnormal termination?

后端 未结 7 1757
無奈伤痛
無奈伤痛 2021-01-17 12:34

My program (a text-mode web browser) is dynamically allocating memory.

I do free unneeded blocks during runtime, of course. And I do free everything before normal te

7条回答
  •  日久生厌
    2021-01-17 12:52

    In my opinion freeing the memory on crash isn't necessary. When your process terminates, OS will reclaim the memory, so all you have to do is exit.

    On the other hand, other resources (e.g. open files) should be closed or at least flushed -- if not, they may not be stored/stored incomplete because of the buffering.

提交回复
热议问题