Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPad receiving memory warning with low memory use

I have an UIWebKit with a HTML, this HTML have several images and text, but just displaying it gives me the memory warning. So I did some tests: The same HTML with different images, fullsize, and after the same images but reduced 50% from it's original size, for the 50% reduced images, I went to preview and reduced all images in 50%

The surprising part is the 50% test, you can see that even with 16 images, the memory peak is 4.90MB. That's really surprising. Notice that these values are not always the same, they change but there's not a huge difference between the tests.

In the 50% issue, in the 8 and 16 images, although the memory is low, sometimes a memory warning appears, but the performance enhance is noticeable compared to the full size images

standing still = memory after scrolling all article

1 Image = [standing still 5MB] [rotating 5.6MB]

2 Images = [standing still 6.99MB] [rotating 7.7MB]

3 Images = [standing still 9.04MB] [rotating 10.9MB]

4 Images = [standing still 10.89MB] [rotating 13.20MB]

8 Images = [standing still 23.14MB] [rotating 25.20MB] (sometimes crashes)

16 Images = [standing still 27.14MB and app crashes]

50%

1 Image = [standing still 3.2MB] [rotating 3.67MB]

2 Image = [standing still 3.2MB] [rotating 3.70MB]

3 Image = [standing still 3.3MB] [rotating 3.79MB]

4 Image = [standing still 3.3MB] [rotating 3.80MB]

8 Images = [standing still 4.29MB] [rotating 4,63MB] (sometimes crashes)

16 Images = [standing still 4.79MB] [rotating 4,90MB] (sometimes crashes)

My question is: The app sometimes crashed with 16 small images. Why? The memory was much lower.

What is the limit of memory use?The maximum seemed different with the 50% size images. 13.2MB works for large images and 3.8 for small images. Anything higher sometimes crashes. That makes no sense.

Thanks

like image 988
Fer Avatar asked May 29 '10 16:05

Fer


1 Answers

It would help if you posted a crash log of what's going on, because it's very likely the crash isn't related as much to your memory consumption as it is to how you're handling that memory. Yes your image size may be exaccerbating the problem, since the amount of real memory used per image is sized according to this formula:

w * h * 4

assuming of course, that the image is a 32-bit colour image, where w is the width of the image in pixels, and h is the height of the image in pixels. As a result, a 1024x1024 32-bit colour image will use approximately 4.2 MB of memory, whereas a 512x512 32-bit colour image will use 1 meg.

Your crash report will be telling. Also running in Instruments under the object allocations and leaks tool may be of tremendous insight (run with the side pane visible, it will show the call stack for any leaks you find). Also note, if you do find leaks that point at things like CIOImage or the like, that may be where the leak eventually occurs, but where the leak is happening will almost positively be in your code.

Also, when running Instruments, remember to run it attached to the app that is running on your device; don't take anything the sim says at face value in cases like this.

like image 115
jer Avatar answered Oct 27 '22 01:10

jer