简体   繁体   中英

UIImage takes a lot of memory when loaded from file

In my iPad app at one moment I load 100 images from Photo Stream using ALAsset and following code:

  ALAsset *asset = [assets objectAtIndex:[sender tag]];
  ALAssetRepresentation *representation = [asset defaultRepresentation];
  UIImage *image = [[UIImage alloc] initWithCGImage:[representation fullScreenImage]
                                                     scale:1.0f
                                               orientation:0];

And everything works perfectly. But when I cache it to the file system as JPEG files, and then load them again with UIImage *image = [UIImage imageWithContentsOfFile:fullPath] , application crashes with Memory Warning, and I can see in the profiler that it really uses a lot of RAM. Why is this happening?

One thing,

When you are loading the image from gallery, why not store the AssetURL , instead of the UIImage ; that should take less space and increase speed.

When you need to show, use the thumbnail representation, perhaps?

Ok, it was my bad. I found the problem, and it comes out that I have memory problems in any case. ALAsset and imageWithContentsOfFile are working exactly the same.

Now I will try to find the way to reduce each image's size.

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