简体   繁体   中英

Clear memory used by UIImage — UIImageView.image = nil doesn't do it

I have created an UIScrollView that contains photos, like in the Photos app.

Photos are downloaded. Images are set through:

imageView.image = [UIImage imageWithData:downloadedImageData];

To save memory, when the user goes far from a photo, I set

imageView.image = nil;

This doesn't clear the memory, though. "Memory Leaks" from Instruments doesn't show any memory leaks.

Can anyone recommend me how to optimize the memory used by images?

[UIImage imageWithData:] is autoreleased object, so it will be freed somewhere in run loop. To release it for sure, use alloc/init constructor.

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