I use ScreenCaptureKit, CoreVideo, CoreImage, CoreMedia frameworks to capture screenshots on macOS 14.0 and higher.
Example of creating CGImageRef:
CVImageBufferRef cvImageBufferRef = ..;
CIImage* temporaryImage = [CIImage imageWithCVPixelBuffer:cvImageBufferRef];
CIContext* temporaryContext = [CIContext context];
CGImageRef imageRef = [temporaryContext createCGImage:temporaryImage
fromRect:CGRectMake(0, 0,
CVPixelBufferGetWidth(cvImageBufferRef),
CVPixelBufferGetHeight(cvImageBufferRef))];
I have the next results of profiling with XCode Instruments Memory Leaks & Allocations: there is constantly increasing memory usage, but no memory leaks are detected, and there are many calls to create IOSurface objects, that have been never released. The most part of memory - All Anonymous VM - VM: IOSurface. The heaviest stack trace:
[RPIOSurfaceObject initWithCoder:]
[IOSurface initWithMachPort:]
IOSurfaceClientLookupFromMachPort
I don't have any of IOSurface objects created by myself. There are low-level calls to it. In Allocation List I can see many allocations of IOSurface objects, but there are no info about releasing it.
Due to this info, how can I release them to avoid permanent increasing memory consumption?