Leak detection is made every time a process is cleanly exiting. It doesn't work if the process is terminated with TerminateProcess() or TerminateThread() / ExitThread() for the last thread in the process; but for most applications this is not a problem.
To enable leak detection when the process is exiting, set the registry key as follows: