【问题标题】:Why fresco chose not put bitmap in ashmem on android 5.0 or higher为什么 fresco 选择不在 android 5.0 或更高版本的 ashmem 中放置位图
【发布时间】:2016-03-20 22:10:29
【问题描述】:

正如 git hub 上的 Fresco 项目所说:“在 Android 4.x 及更低版本中,Fresco 将图像放在 Android 内存的一个特殊区域中。这可以让您的应用程序运行得更快 - 并且更少地遭受可怕的 OutOfMemoryError。”

this 回答,我知道它使用 ashmem 来放置位图。

我的问题是:为什么 fresco 不将位图放在 android 5.0 或更高版本的 ashmem 中? Android 是否会更改某些系统功能并将其禁用?

【问题讨论】:

  • 什么是ashmem

标签: android memory-management bitmap fresco


【解决方案1】:

是的,Google 在 Android 5.0 中禁用了可清除位图。

【讨论】:

    【解决方案2】:
      you can see here 
    

    https://android.googlesource.com/platform/frameworks/base/+/android-cts-7.1_r2/graphics/java/android/graphics/BitmapFactory.java

     /**
         * @deprecated As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this is
         * ignored.
         *
         * In {@link android.os.Build.VERSION_CODES#KITKAT} and below, if this
         * is set to true, then the resulting bitmap will allocate its
         * pixels such that they can be purged if the system needs to reclaim
         * memory. In that instance, when the pixels need to be accessed again
         * (e.g. the bitmap is drawn, getPixels() is called), they will be
         * automatically re-decoded.
         *
         * <p>For the re-decode to happen, the bitmap must have access to the
         * encoded data, either by sharing a reference to the input
         * or by making a copy of it. This distinction is controlled by
         * inInputShareable. If this is true, then the bitmap may keep a shallow
         * reference to the input. If this is false, then the bitmap will
         * explicitly make a copy of the input data, and keep that. Even if
         * sharing is allowed, the implementation may still decide to make a
         * deep copy of the input data.</p>
         *
         * <p>While inPurgeable can help avoid big Dalvik heap allocations (from
         * API level 11 onward), it sacrifices performance predictability since any
         * image that the view system tries to draw may incur a decode delay which
         * can lead to dropped frames. Therefore, most apps should avoid using
         * inPurgeable to allow for a fast and fluid UI. To minimize Dalvik heap
         * allocations use the {@link #inBitmap} flag instead.</p>
         *
         * <p class="note"><strong>Note:</strong> This flag is ignored when used
         * with {@link #decodeResource(Resources, int,
         * android.graphics.BitmapFactory.Options)} or {@link #decodeFile(String,
         * android.graphics.BitmapFactory.Options)}.</p>
         */
        @Deprecated
        public boolean inPurgeable;
    

    【讨论】:

      【解决方案3】:

      Fresco documentation 他们提到:

      Android 5.0 及更高版本比早期版本的内存管理有了很大改进,因此将位图缓存留在 Java 堆上更安全。

      【讨论】:

        猜你喜欢
        • 2017-06-23
        • 2015-03-06
        • 1970-01-01
        • 1970-01-01
        • 2020-07-01
        • 2016-12-11
        • 2022-01-18
        • 2018-06-19
        • 1970-01-01
        相关资源
        最近更新 更多