本文介绍了需要KillTimer吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用SetTimer API,并且看到很多这样的代码:

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;

我是否必须调用KillTimer,否则系统将在进程退出时自动释放资源?忘记致电KillTimer是否会导致资源泄漏?

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?

我知道,如果不需要计时器,则可以由KillTimer销毁它.但是必须手动销毁吗?

I understand that if the timer is not needed it CAN be destroyed by KillTimer. But MUST it be destroyed manually?

推荐答案

HWND中设置的计时器被要销毁的窗口(hwnd)隐式销毁.因此,不,当窗口退出时,您不必清理计时器.

Timers set from HWNDs 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.

这篇关于需要KillTimer吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 17:37