Duplicate: What REALLY happens when you don’t free after malloc?
Let's say, for example:
int main()
{
char* test = new char[50000];
return 0;
}
What happens to the allocated memory after the program had finished? Does it get freed for other applications immediately? Or perhaps after some time? Or maybe it's lost to the system forever? Or does it get swapped to the disk never to return to RAM? Or maybe something completely different?
I would like to know what happens on the major 3 OS's: Windows (XP and up, if there are any differences), Linux, Mac OS X.
See: What REALLY happens when you don't free after malloc?
On any O/S with a MMU (which includes Unix, Linux, OSX and the Windows NT family) the process has a data structure that is used to set up page mappings for tbe MMU. When the process is terminated this mapping is released and the pages are added to the Operating System's free pool.
On non protected-memory O/S platforms such as DOS or some realtime operating systems the memory may need to be explicitly freed and the O/S pool could possibly leak memory if it is not tidied up correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With