Fix macos memory leaks

This commit is contained in:
AuroraWright
2024-02-27 10:30:00 +01:00
parent 608e97c974
commit c361747e69
2 changed files with 21 additions and 18 deletions

View File

@@ -344,6 +344,7 @@ class AppleLiveText:
else: else:
raise ValueError(f'img_or_path must be a path or PIL.Image, instead got: {img_or_path}') raise ValueError(f'img_or_path must be a path or PIL.Image, instead got: {img_or_path}')
with objc.autorelease_pool():
req = VKCImageAnalyzerRequest.alloc().initWithImage_requestType_(self._preprocess(img), 1) #VKAnalysisTypeText req = VKCImageAnalyzerRequest.alloc().initWithImage_requestType_(self._preprocess(img), 1) #VKAnalysisTypeText
req.setLocales_(['ja','en']) req.setLocales_(['ja','en'])
self.result = None self.result = None

View File

@@ -36,6 +36,7 @@ except ImportError:
pass pass
try: try:
import objc
from AppKit import NSData, NSImage, NSBitmapImageRep, NSDeviceRGBColorSpace, NSGraphicsContext, NSZeroPoint, NSZeroRect, NSCompositingOperationCopy from AppKit import NSData, NSImage, NSBitmapImageRep, NSDeviceRGBColorSpace, NSGraphicsContext, NSZeroPoint, NSZeroRect, NSCompositingOperationCopy
except ImportError: except ImportError:
pass pass
@@ -682,6 +683,7 @@ def run(read_from=None,
win32clipboard.CloseClipboard() win32clipboard.CloseClipboard()
elif mac_clipboard_polling: elif mac_clipboard_polling:
if not paused: if not paused:
with objc.autorelease_pool():
old_count = count old_count = count
count = pasteboard.changeCount() count = pasteboard.changeCount()
if not just_unpaused and count != old_count and NSPasteboardTypeTIFF in pasteboard.types(): if not just_unpaused and count != old_count and NSPasteboardTypeTIFF in pasteboard.types():