![]() |
Regarding the heap.
The memory allocated to the heap in a program gets wiped/deleted when the computer shuts Off right? I'm makin a program that uses it but its still in the testing state so some of the heap allocated remains every now and again.
|
The memory allocated to the heap should be freed when you close your application, regardless if you reboot or not. It is up to your program to free up used ressources, at least as long as you are not using a language with automatic garbage collection, IIRC.
|
Quote:
When your program exits, the OS will reclaim all of the memory allocated for that program's heap. It doesn't matter if the program has some memory leak and fails to release some of its heap. The OS takes it back anyway when the program exits. If the OS is shut down or crashes, all the memory allocations are effectively released regardless of whether those processes exited properly. The OS starts fresh when rebooted. But make sure you know the difference between OFF and HIBERNATING. When the computer is hibernating, processes keep their allocated memory. While your process is running, assuming the language or program doesn't have automatic garbage collection, the program is responsible for deleting memory it no longer needs. If it fails to do so, that memory is tied up as long as the process exists. But will be released anyway when the process is gone. |
Quote:
|
Oh man Im used to posting in a C++ fourm. My languige is C++ (der). I am pretty sure it doesnt have automatic grabade collection.
I thought that heap memory would remain allocated until the program ends_it whether or not the program ends. (I dont know how to word that differently) |
Quote:
Quote:
But anyway, it is what you thought (past tense). Now I hope you understand heap memory is freed back to the OS when the program exits. If the program frees memory but does not exit, that memory might be freed back to the OS so other programs can use it, but typically not. Typically memory your program frees goes into a pool within that process that only that process can reuse. That memory is freed back to the OS when the process exits. If you allocate a very large chunk of memory then free it, it probably goes directly back to the OS when freed. If you allocate many small chunks of memory, then free them, the large chunk created by consolidating contiguous small chunks of free memory could be released back to the OS, but probably won't be. |
| All times are GMT -5. The time now is 11:41 PM. |