简体   繁体   中英

Store filename or object of UIImage for processing in Obj-C

I'm currently working on an app that processes multiple images. I receive images as UIImage and save them to a temporary folder on the phone. Afterwards I create an object, which has the UIImage and some meta data as its properties. After loading all images they get processed through OpenCV. I'm wondering if it would optimize the overall performance if I just save the file path instead of holding a reference to the actual UIImage throughout the whole process and then load the UIImage upon request.

It would really help if someone could describe a best practice for this scenario.

Holding a bunch of images in memory ties up memory. You're at risk of running out of memory and crashing.

Saving them to temporary files, building an array of paths, and then loading and processing one image at a time will reduce your memory footprint.

If the images are small and their aren't that many of them then it would probably be faster to simply process them in memory when you first receive them rather than saving them to disk and then reloading them.

You'll have to do some analysis of the total number/size of images and decide where the best tradeoff lies. (Remember that images usually take a LOT more memory than their file size would suggest.) When you load a UIImage into memory it takes 3 or 4 bytes per pixel (4 if their is an alpha channel).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM