dangers of _exit() - memory leak?

随声附和 提交于 2019-12-01 06:25:21

问题


Sorry to repeat a question that has been posed repeatedly, but i couldn't find a specific mention of memory issues. if a process terminates with _exit(0) or _Exit(0) can its memory block be lost to the OS? Thanks, -nuun


回答1:


For just about any consumer O/S that will not happen. Modern multi-process Operating Systems will release any resources the process may have acquired (memory, locks, open files, etc) when the process shuts down. So I generally feel that memory or resource leaks "don't count" as leaks if I just acquire them at startup (not during runtime possibly repeatedly).

However, there are still lots of embedded/realtime platforms out there for which that is not true. If your program might be run on one of those, you should be scrupulous about freeing up acquired resources. But even there it is often easier to just reboot the device after each use...




回答2:


Not on any decent modern O/S (Unix, Windows, whatever) - the O/S will reclaim the process's memory when the process dies, regardless of how cleanly it died.




回答3:


In general, no. Operating systems handle that stuff for us.



来源:https://stackoverflow.com/questions/3720872/dangers-of-exit-memory-leak

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!