I am creating a mac app in which I am converting the CGImageRef to NSData and then Base64 and sending on a server.
This thing happens in Loop, and every time image converted in NSData app memory usage increase.
Here is my code
CGImageRef screenShot = CGWindowListCreateImage(CGRectInfinite, kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageDefault);
bitmapRep = [[NSBitmapImageRep alloc] initWithCGImage: screenShot];
NSData *imageData = [bitmapRep representationUsingType:NSPNGFileType properties:nil];;
NSString *base64String = [imageData base64EncodedStringWithOptions:0];
Please let me know if I am doing any mistake, Thank you
What about CGImageRelease(screenShot)
? I think it should help. Call it when you're done. Seems like you're not releasing the memory that you have received with CGWindowListCreateImage