Fix retained screen-capture surfaces and bound image concurrency - #10
Fix retained screen-capture surfaces and bound image concurrency#10pick7 wants to merge 1 commit into
Conversation
|
Thanks for digging into this and sharing the test results. The I’d rather keep this PR focused on that. Screenshot work is already serialized on the main queue, so I don’t think we need another semaphore or a user-facing concurrency setting here. Those changes also add latency and a new timeout, so they’d be better discussed in a separate PR. Same for changing the screenshot fallback order — it may be a useful optimization, but it changes the capture path and needs its own compatibility testing. Could you keep this PR to the ownership fix and the small cleanup changes? If possible, please also rerun the memory test with only the ownership fix enabled, just to confirm that it fixes the leak by itself. |
Summary
Repeated screenshot and OCR requests could retain IOSurface-backed capture images inside SpringBoard, causing memory usage to grow continuously.
This change:
The public MCP tool schemas, screenshot format, and point-space coordinate metadata remain unchanged. Existing capture fallbacks are retained.
Build environment
88506b2c22e9e07dd4ed055f23c9e398a117a2c7Both the tweak and preference bundle compiled successfully.
Runtime environment
Runtime validation was performed on this environment. Other iOS versions were not runtime-tested, but the existing fallback paths remain available.
Test procedure
screenshotrequests.ocr_screenrequests./usr/bin/footprintafter each phase.Memory observations
All 82 requests completed successfully in both runs.
The IOSurface category reached approximately 861 MB on 1.2.3. With the patch, it remained at 896 KB throughout the full test.
Isolation check
A build containing only autorelease boundaries, OCR cleanup, and concurrency limiting still grew from 60 MB to 171 MB after ten screenshots, with IOSurface reaching 106 MB.
After adding the capture ownership correction, the same ten-request test changed from 61 MB to 67 MB and returned to 63-64 MB after idle, while IOSurface remained at 896 KB.
Concurrency trade-off
With the default limit of one screen task, mixed four-worker latency increased from 1.397 seconds to 2.429 seconds on average. Screenshot and sequential OCR latency remained effectively unchanged.
Devices with more available memory can select two concurrent screen tasks in Settings.