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

crate leaks incredible amounts of memory on macOS #32

Closed
sporeball opened this issue Dec 19, 2024 · 1 comment · Fixed by #33
Closed

crate leaks incredible amounts of memory on macOS #32

sporeball opened this issue Dec 19, 2024 · 1 comment · Fixed by #33

Comments

@sporeball
Copy link
Contributor

this crate is being used in hackclub/kicad-wakatime, which has been suffering a memory leak for quite some time (tracking issue kicad-wakatime #3). using the Instruments tool on macOS, i've finally isolated the leak to this crate.
kicad-wakatime needs to call get_active_window() repeatedly, which leads to the leak.

i am not sure if the memory leak is present on other operating systems, but on macOS, users have reported potential memory usage of up to 30GB after a few hours.

@sporeball
Copy link
Contributor Author

i think i managed to find where the leak is coming from.

after the last call to get_from_dict():

if let DictEntryValue::_Number(window_id) =
    get_from_dict(dic_ref, "kCGWindowNumber")
{
    let active_window = ActiveWindow {
        window_id: window_id.to_string(),
        process_id: active_window_pid as u64,
        app_name,
        position: win_pos,
        title: win_title,
        process_path,
    };

    return Ok(active_window);
}

CFRelease(window_list_info as CFTypeRef) is not called there - it's only called when the crate is about to return Err(()). add a CFRelease() call just above return Ok(active_window), and the leak is no longer reproducible.

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 a pull request may close this issue.

1 participant