Skip to content

Instantly share code, notes, and snippets.

@benbahrenburg
Created March 5, 2017 23:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benbahrenburg/7820832ed3d3c27645f16571cbc04ae6 to your computer and use it in GitHub Desktop.
Save benbahrenburg/7820832ed3d3c27645f16571cbc04ae6 to your computer and use it in GitHub Desktop.
UIImageJPEGRepresentation wrapped within an Autorelease Pool
func UIImageToDataJPEG2(image: UIImage, compressionRatio: CGFloat) -> Data? {
return autoreleasepool(invoking: { () -> Data? in
return UIImageJPEGRepresentation(image, compressionRatio)
})
}
@santhoshs5
Copy link

Dear benbahrenburg,

I am also facing memory issues with compression I am reducing the size of the image first and then getting data with UIImageJPEGRepresentation applying metadata on this data cgimage properities. I am doing this using OpeationQueue for each operation does this job and upload to the server.Some times memory is going 400 to 500 MB. But the same code is working perfectly in Objective C .Can you tell me what can be my issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment