From what I know, for the most part, the OS will free any process memory when the process terminates, at least under most common user OSes (Windows, Linux, etc). The OS will also perform cleanup if the process crashes or such.
HOWEVER, relying on the OS to perform cleanup is not proper coding procedure and you can't always guarantee it'll do what you want. You should always perform your own garbage collection if you want it done right and at the right time (I've had programs crash during exit because the system cleaned up memory in an odd order and created some invalid pointers, that it then tried to free).
Process memory cleanup may only apply to memory allocated by your original process or thread. If you spawn new processes, these could keep executing. If you use an already-running service and call some method that allocates memory then gives you control, that may not get cleanup up.
Some video drivers won't free VRAM immediately and on some older cards, running a process that leaked VRAM repeatedly would eventually crash your system.
You should always free any memory you allocate, especially if your process may restart or keep executing.