The answer will of course depend on the operating system, but in general the OS will go through and sweep up any remaining allocated/mapped memory when the program terminates. In the case of Linux, the cleanup will be completed before the process terminates (enters Z state).