Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is KillTimer really necessary?

Tags:

timer

winapi

This may seem to be a duplicate question for Is KillTimer necessary?, but i would like to confirm this with credible source.

Does destroying window really free the resource allocated by the OS for the timer? (does DestroyWindowsTimers really get called let alone if such function actually exists? if so, where?)

like image 504
JosephH Avatar asked Dec 04 '11 05:12

JosephH


2 Answers

No, it is not necessary. From the documentation of DestroyWindow (with emphasis added):

The function sends WM_DESTROY and WM_NCDESTROY messages to the window to deactivate it and remove the keyboard focus from it. The function also destroys the window's menu, flushes the thread message queue, destroys timers, removes clipboard ownership, and breaks the clipboard viewer chain (if the window is at the top of the viewer chain).

like image 92
Gabe Avatar answered Nov 11 '22 05:11

Gabe


Doing a google search the only actual real looking reference to it looked to be some Win2k source code. The url ended with /Censorship/win2k_sources/private/.../timers.c, I'm assuming from the source code leak a while back. I did not look at the code, nor will I post a link here.

That function most likely exist - something like that almost has to exist for timers linked to window handles - since the timer message is delivered to a specific window handle.

I can't see anywhere in the documentation that states that you don't have to call KillTimer to get rid of a timer. So based on the documented contract, you need to call KillTimer. In practice Windows will probably clean it up for you, but since that is undocumented behavior you should write your code to follow the documented behavior and call KillTimer on all your timers.

like image 2
shf301 Avatar answered Nov 11 '22 06:11

shf301