I use SetTimer
API and I see a lot of code like this:
case WM_DESTROY:
// Destroy the timer.
KillTimer(hwnd, IDT_TIMER);
PostQuitMessage(0);
break;
Do I have to call KillTimer
or the system will automatically free resources on the process exit? Does forgetting to call KillTimer
lead to resource leaks?
I understand that if the timer is not needed it CAN be destroyed by KillTimer
. But MUST it be destroyed manually?
Timers set from HWND
s are implicitly destroyed by the window (hwnd
) being destroyed. So no, you don't have to clean up your timers when the window exits.
But it's a good practice to have all your resources related to the window cleaned up on window close.