将 CGImageRef 转换为 NSData 会增加 Mac 应用中的应用内存使用

Converting CGImageRef to NSData increase app memory usage in Mac app

我正在创建一个 mac 应用程序,我在其中将 CGImageRef 转换为 NSData,然后将 Base64 转换为服务器。

这个事情发生在循环中,每次在 NSData 中转换图像时应用程序内存使用量都会增加。

这是我的代码

CGImageRef screenShot = CGWindowListCreateImage(CGRectInfinite, kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageDefault);
bitmapRep = [[NSBitmapImageRep alloc] initWithCGImage: screenShot];


NSData *imageData = [bitmapRep representationUsingType:NSPNGFileType properties:nil];;
NSString *base64String = [imageData base64EncodedStringWithOptions:0];

如果我做错了请告诉我, 谢谢

CGImageRelease(screenShot)呢?我认为它应该有所帮助。完成后调用它。似乎您没有释放通过 CGWindowListCreateImage

收到的内存