本文介绍了Android 5.0不支持BitmapFactory.Options inPurgeable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Facebookfresco lib.我看到使用inPurgeable选项在ashmem上存储位图非常好.它使我们非常注意内存管理,但是在Davilk heap上减小了OutOfMemoryError.我不知道为什么Android 5.0不连续支持BitmapFactory.Options inPurgeable.
ART有什么变化吗?
谁能解释我的原因?预先感谢.

I'm learning the fresco lib of Facebook. I see that storing bitmap on ashmem with the option is inPurgeable so great. It takes us a lot of care about memory management but decreases OutOfMemoryError on Davilk heap.I wonder why Android 5.0 doesn't continously support BitmapFactory.Options inPurgeable.
Are there any changes in ART?
Can anyone explain the reason for me? Thanks in advance.

编辑
根据Ed George的回答:
为什么Facebook工程师仍然从Android 3.0-> 4.4使用inPurgeable?
他们是否为了获得可预测的性能而折衷Dalvik堆分配?

EDIT
According to Ed George's answer:
Why do Facebook engineers still use inPurgeable from Android 3.0 -> 4.4?
Do they trade off Dalvik heap allocations for performance predictability?

推荐答案

此问题在Fresco的博客文章.请参见可清除的位图"和同时吃蛋糕"部分.如果使用Fresco,您将获得更快的性能和更少的OOM,并且不会失去性能可预测性.

This was answered in Fresco's blog post. See the section on "Purgeable bitmaps" and "Having our cake and eating it too". If you use Fresco, you will get the faster performance and fewer OOMs, and you won't lose performance predictability.

请注意,尽管Fresco在管理位图内存方面也遇到了很多麻烦,但请务必小心避免内存泄漏并尽快关闭位图.如果您尝试自己使用NDK而不是使用Fresco,则需要同样小心.

Note though Fresco also goes to a lot of trouble to manage bitmap memory, being very careful to avoid memory leaks and close bitmaps as soon as possible. If you tried using the NDK yourself instead of using Fresco, you'd need to be equally careful.

Google可能还构建了类似Fresco的解决方案作为Android API的一部分,但他们选择不这样做.公平地说,Android 5.0进行了许多改进,使位图分配比以前更轻松.诸如位图之类的大对象放置在堆上的单独内存空间中,并分别进行垃圾回收,这要快得多.因此,也许他们觉得足够了.

Google could have also built a Fresco-like solution as part of the Android API, but they chose not to. To be fair, Android 5.0 has a number of improvements that make bitmap allocation less painful than it was earlier. Large objects like bitmaps are placed in a separate memory space on the heap and garbage-collected separately, which is much faster. So perhaps they felt that was enough.

这篇关于Android 5.0不支持BitmapFactory.Options inPurgeable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 15:21