Repository navigation
Fix macOS memory leak in app info provider (instead of restarting espanso daily) - #2632
Merged
Merged
Conversation
Closed
Collaborator
|
For some reason CI didn't run tests for macos ¯\_(ツ)_/¯ Fixed in d56f154 Can you rebase on the latest dev? I imagine some clippy lints will fail, but hopefully the macos tests will pass. |
Add @autoreleasepool blocks to Objective-C functions in espanso-info/src/cocoa/native.mm that query active application info. Without autorelease pools, NSRunningApplication and related objects created by methods like [NSWorkspace frontmostApplication] were never released when called from Rust threads, causing memory to grow unboundedly (~1.8GB over 10 days with default 400ms cache interval). Changes: - Wrap info_get_title() in @autoreleasepool - Wrap info_get_title_fallback() in @autoreleasepool - Wrap info_get_exec() in @autoreleasepool - Wrap info_get_class() in @autoreleasepool - Fix info_get_title() to return result instead of hardcoded
The previous commit (0abd1c6) fixed memory leaks in espanso-info by adding @autoreleasepool blocks. This commit applies the same fix to all other Objective-C files in the codebase that were missing autorelease pool protection. Without autorelease pools, autoreleased Cocoa objects created from Rust threads, GCD blocks, and event handler callbacks accumulate indefinitely and are never freed.
Author
done |
Collaborator
|
Many thanks @dmgerman! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The espanso worker process was consuming ~1.8 GB of memory despite having only
~45 simple text triggers configured. The process had been running for 10 days.
Memory usage observed:
The Objective-C functions that query macOS for active application information
were missing
@autoreleasepoolblocks.When methods like
[NSRunningApplication runningApplicationWithProcessIdentifier:]or
[[NSWorkspace sharedWorkspace] frontmostApplication]are called, theyreturn autoreleased objects. In Cocoa, autoreleased objects are added to an
autorelease pool and freed when that pool drains.
However, these functions are called from Rust threads that don't have an
autorelease pool. Without a pool, the autoreleased objects accumulate
indefinitely until the thread exits.
It is now down to approximately 20-30 MBytes of usage.