Originally Posted by Zssfssz
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)
Better wording would have helped.
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.