Just for fun I created a project that created about 5 GB of memory and did not delete it. As long as the application is running that "memory leak" is there. The second I close my application the memory within 2 seconds is back down to normal as if my program never ran. So the questions have to be asked.
Does Windows 7 clean up memory leaks from bad programs when they are done?
Do all Windows versions do this?
Will Linux and Mac OS X environments do this?
When the program terminates, the operating system reclaims all the memory that had previously been allocated to it. Cleaning up memory leaks may be a perceived by-product of this, but the OS does not actually see it that way. It does not know that the program had been leaking memory, just that it had allocated it.
Once a process in which your application runs exits, the OS reclaims all the memory allocated to the process.
This is typically true for all operating systems not just Windows 7 or Windows for that matter.
Note that, you may observe different behavior for other leaking resources like file handles etc, usually OS'es dont reclaim those. So, it is usually(Yes,there are exceptions) a good practice to make your own application clear the mess(deallocate the allocated resource) that it made instead of delegating it to the OS.
Not only does the program manages memory but does the OS too. And it reclaims all the memory allocated to a program after it exist. It doesn't interfere in between the execution of the program (Other than for paging and swapping). This control over memory of the OS helps the OS from crashing from memory leaks to a point.
Memory management is the act of managing computer memory. The
essential requirement of memory management is to provide ways to
dynamically allocate portions of memory to programs at their request,
and freeing it for reuse when no longer needed. This is critical to
the computer system.
BSD Unix normally starts reclaiming memory when the percentage of free memory drops below 5% and continues reclaiming until the free memory percentage reaches 7%
- Yes (Windows 7 does reclaim all memory allocated to a program when the program exits, regardless of how it exits — under control or when crashing).
- Yes (for any version of Windows that's recent enough to be still running).
- Yes (Unix, Linux, Mac OS X, BSD all reclaim all memory allocated to a program when the program exits, regardless of how it exits).
A few old operating systems did not reacquire resources when a program exited. I believe AmigaOS was one; another, I believe, was the old Mac OS (Mac OS 9 and earlier). However, substantially all true multi-tasking systems have to reclaim memory (and resources in general) when the process to which it was allocated exits.
This is not the case for all OS's, for example, I do not believe WinXP will behave this way.
Though for most modern OS's it is now the case. I believe all current versions of Linux, Windows and MacOS do this.
For windows, I'm pretty sure it was introduced in Windows Vista. At the time it was a rather exciting improvement as there were A LOT of dodgey windows applications out there that didn't manage their memory well. At the time it was a big win for windows, but it had come late to the party (as usual), as Linux and MacOS were already doing it long before.
Having said that, I'm sure you appreciate that you definitely still need to manage your memory properly within your application and not simply rely upon your OS to clean up after you. Applications need to be efficient and predictable with their memory use during their runtime as well.