iPad receives memory warning, low memory usage

I have a UIWebKit with HTML, this HTML has a few images and text, but just showing it gives me a memory warning. So I did some tests:
Same The HTML has different images, full size and the same image, but reduced from the original size by 50%, for the 50% reduced image, I go to preview and reduce all images by 50%

The surprising part is the 50% test, you can see that even with 16 images, the memory peak is 4.90MB. This is really surprising.
Please note that these values ​​are not always the same, they Will change but there is not much difference between the tests.

In 50% of the problems, in 8 and 16 images, although the memory is low, sometimes a memory warning appears, but it is different from the full size Compared with images, the performance improvement is obvious

After scrolling all the articles, stand still=memory

1 picture= [stationary 5MB] [rotating 5.6MB]

2 images = [stationary 6.99MB] [rotating 7.7MB]

3 images = [stationary 9.04MB] [rotating 10.9MB]

4 Images = [stationary 10.89MB] [rotating 13.20MB]

8 images = [stationary 23.14MB] [rotating 25.20MB] (crash sometimes)

16 pictures = [stationary 27.14MB and app crash]

50%

1 image = [stationary 3.2MB] [rotating 3.67MB]

< p>2 images = [stationary 3.2MB] [rotating 3.70MB]

3 images = [stationary 3.3MB] [rotating 3.79MB]

4 images = [ Still 3.3MB] [Rotating 3.80MB]

8 images = [Still 4.29MB] [Rotating 4,63MB] (crash sometimes)

16 images = [Stationary 4.79MB] [Rotating 4,90MB] (Sometimes it crashes)

My question is: The application sometimes crashes with 16 small images. Why? Memory is much lower.

What are the limits of memory usage? The maximum value for 50% of the size of the image seems to be different. 13.2MB is for large images, 3.8 is for small images. Anything higher sometimes crashes. It makes no sense.

Thank you

It’s helpful if you post a crash log that is happening, because the crash is likely to be related to your memory consumption It has nothing to do with the way you handle memory. Yes, the size of your image may seriously affect the problem, because the actual amount of memory used by each image is determined by the following formula:

w * h * 4

Of course, suppose the image is a 32-bit color image, where w is the width of the image (in pixels) and h is the height of the image (in pixels) ). Therefore, a 1024×1024 32-bit color image will use about 4.2 MB of memory, and a 512×512 32-bit color image will use 1 meg.

Your crash report will tell you. Also in the object Running the tool under the allocation and leak tool can have great insight (run with the side pane visible, and it will show the call stack of any leaks you find). Also note that if you find that the leak is pointing to something like CIOImage This may be the place where the leak will eventually occur, but the place where the leak occurred will almost certainly appear in your code.

Also, when running Instruments, remember to connect it to the device The running application; in this case, don’t take sim for anything that represents the face value.

I have a UIWebKit with HTML, and this HTML has several images And text, but just showing it gave me a memory warning. So I did some tests:
The same HTML has a different image, full size and the same image, but reduced by 50% from the original size, for 50% For reduced images, I go to preview and reduce all images by 50%

The surprising part is the 50% test, you can see that even with 16 images, the memory peak is 4.90MB This is really surprising.
Please note that these values ​​are not always the same, they will change but there is not much difference between tests.

In 50% of the questions, In 8 and 16 images, although the memory is very low, sometimes there will be a memory warning, but compared to the full-size image, the performance improvement is obvious

After scrolling all the articles, stand still = memory< /p>

1 picture = [stationary 5MB] [rotating 5.6MB]

2 pictures = [stationary 6.99MB] [rotating Turn 7.7MB]

3 pictures = [Still 9.04MB] [Rotate 10.9MB]

4 pictures = [Still 10.89MB] [Rotate 13.20MB]

8 images = [stationary 23.14MB] [rotating 25.20MB] (crash sometimes)

16 images = [stationary 27.14MB and app crash]< /p>

50%

1 image = [stationary 3.2MB] [rotating 3.67MB]

2 image = [stationary 3.2MB] [rotating 3.70 MB]

3 images = [stationary 3.3MB] [rotating 3.79MB]

4 images = [stationary 3.3MB] [rotating 3.80MB]

8 images = [stationary 4.29MB] [rotated 4,63MB] (sometimes crashing)

16 images = [stationary 4.79MB] [rotated 4,90MB]( Sometimes it crashes)

My question is: The application sometimes crashes with 16 small images. Why? Memory is much lower.

What are the limits of memory usage? The maximum value for 50% of the size of the image seems to be different. 13.2MB is for large images, 3.8 is for small images. Anything higher sometimes crashes. It makes no sense.

Thank you

It will be helpful if you post a log of a crash that is happening, because the crash is most likely not related to your memory consumption, nor to the way you handle memory. Yes, your image size may seriously affect the problem, because the actual amount of memory used by each image is determined according to the following formula:

w * h * 4 

Of course, assuming that the image is a 32-bit color image, where w is the width of the image (in pixels) and h is the height of the image (in pixels). Therefore, a 1024×1024 32-bit color image will be Use about 4.2 MB of memory, and 512×512 32-bit color images will use 1 meg.

Your crash report will tell you. Similarly, running the tool under the object allocation and leak tool may have great Insight (run with the side pane visible and it will show the call stack of any leaks you find). Also note that if you find that the leak is pointing to something like CIOImage, this may be where the leak will eventually occur, But the place where the leak occurs will almost certainly appear in your code.

In addition, when running Instruments, remember to connect it to the application running on the device; in this case, don't Take sim to represent anything at face value.

Leave a Comment

Your email address will not be published.