dangers of _exit() - memory leak?

2019-02-19 04:15发布

问题:

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.