Remove leaks from macOS clipboard getters #106
Merged
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.
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.frameworkFinally, 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.