iOS:由于内存不足导致浏览器崩溃 [英] iOS: Browser crashes due to low memory

查看:718
本文介绍了iOS:由于内存不足导致浏览器崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于iOS上的内存不足,我的网站在浏览器中崩溃。我正在重复一些消耗内存的动作。经过多次尝试,浏览器崩溃。然而,当我使用开发工具中的timelime使用Chrome在桌面上测试同一网站时:


  1. 执行相同的操作

  2. 收集垃圾

  3. 收集所有额外分配的内存。

如果没有内存泄漏,为什么浏览器会崩溃?有没有办法强制垃圾收集?

解决方案

知道iOS资源限制



您的网页在桌面上表现良好并不能保证它在iOS上表现良好。

1.请记住,iOS使用



    < (更低带宽,更高延迟)
    b
  • Wi-Fi(带宽更高,延迟更低)

  • 连接到互联网。



    2.您需要尽量减少网页的大小。
    包括



    • 未使用或不必要的图片

    • CSS

    • JavaScript
    / blockquote>

    这会对您的网站在iOS上的表现产生不利影响。

    3.由于iOS上的内存可用,限制它可以处理的资源数量:


    已解码的 GIF,PNG和TIFF的最大尺寸 <256 GB RAM >具有大于或等于256 MB RAM的设备的

  • 5百万像素


确保宽度*高度≤3* 1024 * 1024(对于小于256 MB RAM的设备)

注意:解码后的尺寸远大于图像的编码尺寸。

最大解码的i mage 尺寸是使用
subsampling的 32百万像素。由于
子采样的缘故,JPEG图像可以高达<3200万像素,这允许JPEG图像解码为具有像素数量的十六分之一的大小。 >。大于2百万像素的JPEG图像
被二次抽样,即被解码为缩小尺寸。 JPEG子采样
允许用户查看最新数码相机的图像。

4. 最大尺寸一个画布元素是



  • <300万像素对于具有大于或等于256 MB RAM的设备,超过256 MB RAM

  • 5 megapixels
    如果未指定,则画布对象的高度和宽度为150 x 300像素。



<每个顶部的JavaScript执行时间限制为10秒


级入口点。如果您的脚本
执行超过10秒,则iOS上的Safari会停止执行
脚本,因此您的代码中的随机地方会导致意外后果
可能导致


6.可以一次打开的文档的最大数量

  • >
  • 9在iPad上。

  • b $ b

    请参阅为Safari-Apple文档开发Web内容获取更多信息。



    垃圾收集



    移动Safari浏览器的JavaScript实现没有像IE浏览器中的


    re是三个事件,它们会触发
    移动Safari浏览器中的垃圾收集
    Reference )。


    • 专用垃圾收集计时器到期

    • 当所有堆的CollectorBlocks已满时发生分配。

    • 具有足够大关联的对象存储是分配的。


    触发垃圾回收真的是一种糟糕的做法。我们应该做什么是编写不会泄漏内存的代码。

    请参阅


    My site crashes in the browser due to low memory on iOS. I'm repeating some action which consumes memory. After several attempts, the browser crashes. However, when I tested the same site on my desktop using Chrome by using timelime from dev tools:

    1. Perform the same action
    2. Collect garbage
    3. All additionally allocated memory is collected.

    Why does the browser crash if there are no memory leaks? Is there a way to force garbage collection?

    解决方案

    Know iOS Resource Limits

    Your webpage performing well on the desktop is no guarantee that it will perform well on iOS.

    1.Keep in mind that iOS uses

    • EDGE (lower bandwidth, higher latency)
    • 3G (higher bandwidth, higher latency)
    • Wi-Fi (higher bandwidth, lower latency)

    to connect to the Internet.

    2.You need to minimize the size of your webpage. Including

    • unused or unnecessary images
    • CSS
    • JavaScript

    which adversely affects your site’s performance on iOS.

    3.Because of the memory available on iOS, there are limits on the number of resources it can process:

    The maximum size for decoded GIF, PNG, and TIFF images

    • 3 megapixels for devices with less than 256 MB RAM
    • 5 megapixels for devices with greater or equal than 256 MB RAM

    That is ensure width * height ≤ 3 * 1024 * 1024 for devices with less than 256 MB RAM

    Note: that the decoded size is far larger than the encoded size of an image.

    The maximum decoded image size for JPEG is 32 megapixels using subsampling. JPEG images can be up to 32 megapixels due to subsampling, which allows JPEG images to decode to a size that has one sixteenth the number of pixels. JPEG images larger than 2 megapixels are subsampled—that is, decoded to a reduced size. JPEG subsampling allows the user to view images from the latest digital cameras.

    4.The maximum size for a canvas element is

    • 3 megapixels for devices with less than 256 MB RAM
    • 5 megapixels for devices with greater or equal than 256 MB RAM. The height and width of a canvas object is 150 x 300 pixels if not specified.

    5.JavaScript execution time

    limited to 10 seconds for each top-level entry point. If your script executes for more than 10 seconds, Safari on iOS stops executing the script at a random place in your code, so unintended consequences may result.

    6.The maximum number of documents that can be open at once is

    • eight on iPhone

    • nine on iPad.

    Please refer Developing Web Content for Safari-Apple Documentation for more info.

    Garbage Collection

    Mobile safari javascript implementation doesn't have any command like CollectGarbage() in internet explorer for garbage collection.

    There are three events that will trigger garbage collection in mobile safari(Reference).

    • A dedicated garbage collection timer expires
    • An allocation occurs when all of a heap's CollectorBlocks are full.
    • An object with sufficiently large associated storage is allocated.

    Its really a bad practice to trigger garbage collection.What we should be doing is to write codes that doesn't leak memory.

    Plese refer Memory management in Javascript

    这篇关于iOS:由于内存不足导致浏览器崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆