So the compiler is nice enough to take care of this for us. Part of the process the compiler goes through when the program terminates is the freeing of all memory that was used during the program.
A compiler has nothing to do with it; it just delivers compiled object files which
are linked by a linker. The linker produces a certain format file that is condsidered
an executable binary file ('elf' or 'coff' or what have you). When that image is
loaded the instructions are executed; when that process has finished the OS will
remove every trace of it including all memory used by that process. So, yes,
dynamic memory will be lost for the posterity if the process didn't take care of
it itself.
kind regards,
Jos