Skip to content

Conversation

@adrian-niculescu
Copy link
Contributor

@adrian-niculescu adrian-niculescu commented Dec 2, 2025

Summary

  • Clarified the comment in removeTask to better explain the timer cleanup flow
  • Removed stale commented-out code

Context

While investigating timer memory management, I tested uncommenting the CFRelease(timer) call and confirmed it causes a double-free crash. This validates that the current implementation is correct.

The new comment clearly explains the cleanup flow:

  • CFRunLoopTimerInvalidate triggers our TimerRelease callback
  • This deletes TimerContext, whose destructor calls CFRelease(task->timer)

Why this clarification helps

Apple's CFRunLoopTimerInvalidate documentation states:

"The memory is not deallocated unless the run loop held the only reference to timer."

This does not make it obvious that invalidation also triggers the context's release callback, which is what actually handles the cleanup in this implementation.

Test plan

  • Verified that uncommenting CFRelease(timer) crashes (double-free)
  • Confirmed the existing code correctly cleans up timers via the destructor chain

@NathanWalker NathanWalker merged commit b14392e into NativeScript:main Dec 3, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants