The answer is, most often.
Freeing the heap is responsiblity of the OS. While most OS (especially mainstream OS) frees the heap upon exit, it is not necessarily true of say embedded system OS.
When you call for memory to be allocated on the heap, a system call is made to the kernel space of the OS to provide this memory. This memory is mapped to your process structure, which is maintained by the OS. When your program exits, the OS goes through a clean up routing, closing all file descriptors, and marks this memory free for allocation to other processes (among other things).
Some of these answers are incorrect in saying that it is compiler dependant. The compiler does not say 'hey free all this memory on program exit'. That wouldn't make sense, what happens if the OS unexpectedly terminates the program then? No, the compiler is responsible for generating system calls whenever memory allocation/deallocation is explicitly requested for the heap.