Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSA Apple Events trigger memory leak #4

Open
jrr6 opened this issue Jul 6, 2021 · 0 comments
Open

OSA Apple Events trigger memory leak #4

jrr6 opened this issue Jul 6, 2021 · 0 comments

Comments

@jrr6
Copy link
Owner

jrr6 commented Jul 6, 2021

Issue

Using the Caffeinator suite in JXA causes a memory leak when accessing properties on the caffeination object (e.g., options, active).

Steps to Reproduce

The following script will cause about .3–.5 MB to be leaked (whereas the commented bottom-most line—using the Application suite—causes no leak):

for (i = 0; i < 2000; i++) {
    if (Application("Caffeinator").caffeination.active() == true) { "active" } else { "stopped" }
    // if (Application("Caffeinator").caffeination.options() == []) { "none" } else { "some" }
    // console.log(Application('Caffeinator').version())
}

The leak has no correspondence to the size of the data returned by Caffeinator (e.g., causing options to always return a 100-element array leaks no more memory than having options always be empty). Even after replacing ScriptingCaffeination with a dummy class that does no meaningful computation, the leak remains.

After 30 minutes of periodic AppleScript events (triggered by two-second polling by BetterTouchTool), leaked memory totaled approximately 2.4 MB. Over extended use, hundreds of megabytes have been observed to leak. Instruments does not seem to detect these cumulative leaks, but rather detects only a single, initial, 16-byte leak of category Security::CodeSigning::SecStaticCode::ValidationContext. Allocations seem to stem from AEProcessAppleEvent in the call tree.

Proposed Resolution

Continue investigating behavior and source of memory leak. This may have to do with the design of OSA and how scripting is implemented.

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

No branches or pull requests

1 participant