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

Remove leaks from macOS clipboard getters #106

Merged
merged 1 commit into from
Aug 28, 2023

Conversation

complexspaces
Copy link
Collaborator

@complexspaces complexspaces commented Jul 29, 2023

In summary, this PR removes the last of the memory leaks in the macOS clipboard implementation. Specifically, it does two things to accomplish this:

This additionally refactors image() to be simpler by taking advantage of the fact that we only want one image. Additionally, this codepath avoids the highly aggressive system-level caching of image data that can help reduce peak usage. We have applied an autorelease pool to the Obj-C code as well, as there appear to be a lot of autoreleased values used by AppKit.framework

Finally, it applies a similar refactoring to text() for simplicity and removal of memory leaks due to incorrect object retaining assumptions. After a lot of investigation, this seemed to be the best path forward (as previously noted by #97).

Its worth noting that some of the memory growth caused by these functions would have gone away after 5-10 seconds of not calling into the clipboard. However, some use cases require calling into it frequently so this isn't always an option for users.

This additionally refactors `image()` to be simpler by taking advantage
of the fact that we only want one image. Additionally, this codepath avoids
the system-level caching of image data that can help reduce peak usage.
We have applied an autorelease pool to the Obj-C code as well, as there
appear to be a lot of autoreleased values used by AppKit.framework

Finally, it applies a similar refactoring to `text()` for simplicity and
removal of memory leaks due to incorrect object retaining assumptions.

Co-authored-by: taojiacheng <[email protected]>
@complexspaces complexspaces merged commit 7af9a37 into master Aug 28, 2023
7 checks passed
@complexspaces complexspaces deleted the remove-apple-getter-leaks branch October 8, 2023 22:35
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 this pull request may close these issues.

1 participant