Fix resource leaks, race conditions, and perf issues#1
Conversation
…ments Critical fixes: - WindowSelectorController: add didFinish guard + finish(with:) to prevent mouse monitor and overlay window leaks - CaptureCoordinator: fix isCapturing race condition for OCR/timer modes by deferring flag reset to completion notifications instead of resetting immediately; close existing controllers before reassignment - AreaSelectorWindowController: use window.close() instead of orderOut to properly release windows - OCRResultPanel: close old panel before creating new one - TimerCaptureController: add window cleanup in deinit, post finish notification on cancellation Safety: - HotkeyManager: add deinit calling stop(); cap permission retry timer at 40 attempts (60s) to prevent runaway polling - AppState: replace force-unwrap on desktop directory with safe fallback Performance: - BlurAnnotation/PixelateAnnotation: crop source image to annotation rect before applying CIFilter (50-100x faster for 4K screenshots) - CanvasNSView: remove duplicate synchronizeAnnotationSelectionState() call from drawAnnotationSelectionOverlay; add early init in viewDidMoveToWindow - HistoryBrowserView: add 300ms search debouncing - AppState: coalesce UserDefaults writes with 0.5s idle flush - ScreenCaptureService: add 2-second SCShareableContent cache Resource management: - QuickAccessManager: nil panel after orderOut to release view hierarchy - DesktopIconsHelper: replace deprecated synchronize() with CFPreferencesAppSynchronize - HistoryManager: only post historyDidChange on successful save Quality: - Extract triplicated directorySize() into StorageSizeCalculator utility - Remove redundant zOrder/isVisible assignments in CanvasState snapshots - Enable rotation for line annotations
Greptile SummaryThis PR systematically addresses critical resource leaks, race conditions, and performance bottlenecks across the capture pipeline. The changes properly fix memory leaks by replacing Key improvements:
One issue found:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant CaptureCoordinator
participant OCRController
participant TimerController
participant AppState
Note over User,AppState: OCR Capture Flow (Race Condition Fixed)
User->>CaptureCoordinator: Trigger OCR
CaptureCoordinator->>AppState: isCapturing = true
CaptureCoordinator->>OCRController: Post .startOCRCapture
OCRController->>OCRController: Show area selector
alt User completes selection
OCRController->>OCRController: Process OCR
OCRController->>CaptureCoordinator: Post .ocrCaptureDidFinish
else User cancels
OCRController->>CaptureCoordinator: Post .ocrCaptureDidFinish
else Error occurs
OCRController->>CaptureCoordinator: Post .ocrCaptureDidFinish
end
CaptureCoordinator->>AppState: isCapturing = false
Note over User,AppState: Resource Leak Fixes
User->>CaptureCoordinator: Trigger capture (area/window)
CaptureCoordinator->>CaptureCoordinator: Close existing controller
CaptureCoordinator->>CaptureCoordinator: Create new controller
Note over CaptureCoordinator: Prevents controller overwrite leaks
Last reviewed commit: cd551e9 |
Additional Comments (1)
|
Summary
didFinishguards,finish(with:)pattern, andwindow.close()instead oforderOutisCapturingrace condition for OCR/timer modes — flag now resets on completion notifications instead of immediately, preventing double-capturesdirectorySize()to shared utility, clean up redundant snapshot assignments, enable line annotation rotationTest plan
isCapturingresets on both success and cancel🤖 Generated with Claude Code