0

I have an app that has 12 images contained in an array. All these images are displayed at the same time on the screen. (1 view - 12 much wider and higher images (UIImageView's) one on another. When user does something, app moves the images, thus the view displays different scenes) The images themselves are not too heavy (it is about 2500x5000 in size, but the whole folder with images is around 3.5 MB). After loading, the app consumes 355 MB. When I put breakpoint in viewDidLoad (and all images are loaded at that time), xcode shows that the app consumes only 9 MB, but in viewDidAppear it is 355 MB.

What is the reason of it? And how can I store images compactly? (As I assume that the problem is in the images).

Thank you for any help!

2
  • load those images when needed don't keep in the array. Commented Apr 18, 2014 at 11:58
  • 2
    The images are being stored in memory uncompressed. 2500x5000x3 = 35MB per image. Commented Apr 18, 2014 at 11:59

3 Answers 3

2

An image open will occupy something like : H x W x number of channel x number of bit for channel, the file size is another thing, because images are compressed according to their type. Your images are 50Mb each one in memory.
The only way is to resize the image before displaing them. There are plenty of image resizing categories online, just google a little bit. The other suggestion is to not load all the images togheter, just bring in the array the file path, and instantiate the image lazily.
If you need to use hires images you should look for CATiledLayer and tiling techniques.

Sign up to request clarification or add additional context in comments.

Comments

0

These images probably cannot be displayed all at the same time onscreen, so you may want to load them only when necessary.

If you still need to display them all together onscreen, think about reducing their size.

Still, 355Mb is huge. Are you doing anything else in that application, that might use up all of that memory?

1 Comment

They all are on the screen at the same time. It is like - first image is a matrix of haircuts. Second - matrix of noses, third - matrix of eyes. User chooses brown eyes (which is part of the matrix at coordinates 300, 400, for example). The view moves the image so that the selected eyes were visible. This way the image of a boy/girl is drawn. How can I reduce the size of images?
0

In Xcode go to Product->Profile. You will find there a lot of useful instruments which will help you to find problems with memory, CPU or battery usage. However, check it if you haven't seen it before.

1 Comment

Yeah, I used Instruments. I just could not understand why there was so much memory engaged. Now dreamlax explained that. The question is now - how to decrease size of the images in memory (as I totally need them all to be uploaded).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.