I am posting this question as I could not find the answer on googling and stackoverflowing it…
The question is :
What happens when Virtual memory’s swap space is exhausted. How does OS handles this situation when all the RAM and Virtual Memory is exhauseted.
Does it secretly use more space on HDD, Or notify an exception
I am going to assume that by virtual memory you are referring to swap space (they are technically different concepts). I can think of two things:
The program checks to make sure that the allocation went well (ie in C there is a return code for malloc) and if it did not go well, then it will gracefully exit with a once-ubiquitous “Out of memory” Error message. Java and C++ have exceptions for the same purpose.
The program doesn’t check because, really, who runs out of memory anymore? (This is a programmer thinking here.) I would bet that chances are there are many programs written out there that do not check to see if a call to malloc succeeded or not, and therefore they try to use a bad pointer and cause a memory access violation, causing the program to exit with a nice “This program has encountered a problem” message in windows, or a succinct “Segfault” message in Unix.