When a C/C++ program containing the dynamically allocated memory(using malloc/new) without free/delete calls is terminated, what happens to that dynamically allocated memory?
Does the operating system takes back the memory or does that memory becomes unaccessible to other programs?
When a C/C++ program containing the dynamically allocated memory(using malloc/new) without free/delete calls is
Share
I don’t think that there are any guarantees in the language standard, but modern operating systems which support sparse virtual memory and memory protection (such as MacOS X, Linux, all recent version of Windows, and all currently manufactured phone handsets) automatically clean up after badly-behaved processes (when they terminate) and free the memory for you. The memory remains unavailable, however as long as the program is running.
If you’re programming on microcontrollers, on MacOS 9 or earlier, DOS, or Windows 3.x, then you might need to be concerned about memory leaks making memory permanently unavailable to the whole operating system.