Skip to content

OSA Apple Events trigger memory leak #4

@jrr6

Description

@jrr6

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions