After the process finishes, all memory for the process is freed, including memory leaks on the heap. The reason is that when the process is finished, the GDT, LDT, and page directories are changed by the operating system, the logical memory is all gone, the contents of the physical memory may still be in but the logical memory has been removed from the LDT and GDT, the page directory table is all destroyed, so the memory will be fully recovered.
This code, I personally think that can be used as an example, not to please more advice:
[C-sharp]View Plaincopy
- #include <cstdlib>
- using namespace Std;
- const static int const_once = 1024*1024*2;
- int _tmain (int argc, _tchar* argv[])
- {
- int *a;
- for (int cnt=0;cnt<=10;cnt++)
- {
- A = new int[const_once];
- A[10] = 1;
- A[CONST_ONCE-10] = 1;
- }
- System ("pause");
- Exit (0);
- return 0;
- }
Operation Result:
When you pause:
After:
I this program does not account for hundreds of trillion memory, you can try repeatedly, some people always say that memory leaks until the new start to be recycled, I think this is the DOS ERA, DOS there is no paging fragmented virtual storage of these management, so it will always leak it.
Transferred from: http://blog.csdn.net/x50573750/article/details/6171604
After the process finishes, all memory for the process is freed, including memory leaks on the heap.