Skip to content

🐞 Fix memory leak inside CGEventMonitor#694

Merged
mrkai77 merged 1 commit into
mrkai77:developfrom
zenangst:fix/memory-leak-with-cg-event-monitor
Mar 6, 2025
Merged

🐞 Fix memory leak inside CGEventMonitor#694
mrkai77 merged 1 commit into
mrkai77:developfrom
zenangst:fix/memory-leak-with-cg-event-monitor

Conversation

@zenangst

@zenangst zenangst commented Feb 28, 2025

Copy link
Copy Markdown
Contributor

This should help fix the issue where things slow down after a period of usage as it no longer keeps previous event monitors around after looping as it resigned its usage via LoopManager.closeLoop.

Before, event monitor was passed as retained to itself, which quickly created a retain cycle. Also, I added proper cleanup by invalidating the mach port when the event monitor is about to go out of scope.

  • Pass user info as unretained into the callback to avoid the mach port never being released.
  • Invalidate the event tap inside deinit.

- Pass user info as unretained into the `callback` to avoid the mach port never being released.
- Invalidate the event tap inside `deinit`.

@mrkai77 mrkai77 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to now merge this, as it seems to fix the issue based on the latest info from other commenters. Will release a new dev version containing this fix so that a larger audience can participate in testing!

@mrkai77 mrkai77 merged commit e1cd3a8 into mrkai77:develop Mar 6, 2025
@mrkai77 mrkai77 changed the title Fix memory leak inside CGEventMonitor 🐞 Fix memory leak inside CGEventMonitor Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants