UIImage takes a lot of memory when loaded from file

435 views Asked by At

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?

2

There are 2 answers

0
kavalerov On

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.

8
Debanjan On

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?