Would a one-shot timer cause a memory leak?

峻魁 张 20 Reputation points
2024-03-08T16:10:35.4766667+00:00

I created a timer queue, then created some one-shot timer using the below code:

CreateTimerQueueTimer(
	&mut handle,
	self.timer_queue,
	Some(timer_runner),
	Some(ptr as _),
	duration.as_millis() as u32,
	0,
	WT_EXECUTEONLYONCE,
)

I have searched extensively, but none of the sources mention whether the timers will be automatically released if I do not call DeleteTimerQueueTimer, or if it would lead to a memory leak?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,427 questions
{count} votes

Accepted answer
  1. Jeanine Zhang-MSFT 9,181 Reputation points Microsoft Vendor
    2024-03-11T03:05:41.0533333+00:00

    Hello,

    Welcome to Microsoft Q&A!

    Accordng to the Doc: CreateTimerQueueTimer function

    The period of the timer, in milliseconds. If this parameter is zero, the timer is signaled once.

    Although the one-shot timer is only signaled once, the timer is not automatically canceled. As far as I'm concerned, you need to call the DeleteTimerQueueTimer function to cancel a timer.

    Thank you.

    Jeanine


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful