2

My app grabs photo images from a server and stores them in an array which will eventually be displayed in a UITableView Controller.

I am displaying 2 images in a single cell (768 by 768 pixels and 100 X 100 pixels).

At launch, the app will load 10 cells with images and the user can choose to load the next 10 photos using a "load more" button. Usually after 15-20 'load more' clicks, I will receive a memory warning level = 2 message and my app will just terminate.

Is this due to the fact that there are too many images displayed? How can I resolve this issue?

Zhen
  • 12,361
  • 38
  • 122
  • 199

3 Answers3

2

Check out my recent SO question / answer. I think it might help a lot. I used a batch file called PNGCrush to crush / compress my PNG files without loosing quality. My app's memory footprint went from ~60 Mb to ~30 MB. As Jhaliya said, 24 MB of images is probably what's causing Memory Warnings (that's what was happening in my app).

My StackOverflow.com Post

Community
  • 1
  • 1
Sam Spencer
  • 8,492
  • 12
  • 76
  • 133
0

it's happening due to the size of images that you download from web to show in your UITableView cells.

There is one and only one solution of crash to reduce the size of images as much as possible.

@damian: As per your calculation :

1 image = 2.4 mb then 10 images = 24 mb : i think, After having 10 such images in your application the next image with size 2.4 mb is enough to trigger a memory warning of level 2 .

Jhaliya - Praveen Sharma
  • 31,697
  • 9
  • 72
  • 76
  • (768x768 + 100x100) * 4 = ~2.4mb which is big but not enormous. At least one set should fit in memory, and since the max screen size is 1024x768 anyway, this should be enough. – damian Jun 12 '11 at 10:22
  • That depends on what else is occupying the memory (background processes etc.). But in any case good caching will solve this problem, the images don't need to be reduced in size. – damian Jun 13 '11 at 07:03
  • @damian, I am using lazy loading for my 768 by 768 pixels picture which includes caching. However for my smaller pics, I was just using ASIHTTPRequest to fetch the images (and store in array) asynchronously. I believe that is why I have memory warning. – Zhen Jun 19 '11 at 09:35
0

It's difficult to tell from your description what is being displayed on screen at one time. If you're only showing one pair of images at once then you can cache the rest on disk instead of keeping them in memory. If you're showing thumbnails, you can again cache the full sized images on disk, but you should be able to keep all the small thumbnails in memory.

damian
  • 3,604
  • 1
  • 27
  • 46
  • @ damian : plz let me know how much *run time memory* an iphone apps could own ? – Jhaliya - Praveen Sharma Jun 13 '11 at 07:09
  • @Jhaliya that depends on how much is available. I wrote a proof of concept for an app that loaded 12x RGBA 512x512 textures (12mb) for each page of an iPad book. Sometimes we could loud and cache three pages in memory before seeing memory warning level 1, and sometimes the app crashed with memory warning level 2 as soon as we tried to load the second. – damian Jun 13 '11 at 07:30
  • @Jhaliya because he's storing all his images in an 'array' (ie in RAM) and, I assume, ignoring memory warning level 1. – damian Jun 13 '11 at 07:47
  • @ damian : That's why,i indicate the issue with remaining run time memory (ie in RAM) which become very less because of the size of images it has in array . – Jhaliya - Praveen Sharma Jun 13 '11 at 07:58