- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的项目中,我有最简单的 ListView 和适配器,使用 Picasso 加载图像。每个解码图像大约为 140-150 kbytes..但在前 30-60 秒(当 Picasso 内存 LruCache 填充时)滚动是滞后的。
这是 logcat 的一部分:
09-19 14:11:01.435 4676-5700/com.test D/dalvikvm﹕ GC_FOR_ALLOC freed 270K, 11% free 34374K/38228K, paused 60ms, total 61ms
09-19 14:11:01.435 4676-5700/com.test I/dalvikvm-heap﹕ Grow heap (frag case) to 34.487MB for 148408-byte allocation
09-19 14:11:01.505 4676-4676/com.test D/dalvikvm﹕ GC_FOR_ALLOC freed 9K, 11% free 34510K/38376K, paused 66ms, total 66ms
09-19 14:11:06.875 4676-5701/com.test D/dalvikvm﹕ GC_FOR_ALLOC freed 132K, 11% free 34497K/38376K, paused 39ms, total 39ms
09-19 14:11:06.875 4676-5701/com.test I/dalvikvm-heap﹕ Grow heap (frag case) to 34.606MB for 147760-byte allocation
09-19 14:11:06.915 4676-4676/com.test D/dalvikvm﹕ GC_FOR_ALLOC freed <1K, 11% free 34641K/38524K, paused 41ms, total 41ms
09-19 14:11:11.375 4676-5702/com.test D/dalvikvm﹕ GC_FOR_ALLOC freed 110K, 11% free 34650K/38524K, paused 58ms, total 59ms
09-19 14:11:11.385 4676-5702/com.test I/dalvikvm-heap﹕ Grow heap (frag case) to 34.757MB for 149704-byte allocation
09-19 14:11:11.445 4676-4676/com.test D/dalvikvm﹕ GC_FOR_ALLOC freed <1K, 11% free 34796K/38672K, paused 64ms, total 64ms
09-19 14:11:14.615 4676-5699/com.test D/dalvikvm﹕ GC_FOR_ALLOC freed 119K, 11% free 34796K/38672K, paused 53ms, total 53ms
09-19 14:11:14.625 4676-5699/com.test I/dalvikvm-heap﹕ Grow heap (frag case) to 34.900MB for 149704-byte allocation
09-19 14:11:14.655 4676-4676/com.test D/dalvikvm﹕ GC_FOR_ALLOC freed <1K, 10% free 34942K/38820K, paused 37ms, total 37ms
我在这里看到的:
堆会随着图像的下载和解码而增长。
在堆增长之前,Dalvik 尝试 GC 一些内存。
根据每个 GL_FOR_ALLOC,当前 Activity 堆大小大约有 3 MB 可用空间。
对于 ListView 中的每个下一个图像,我们需要大约 300-500kb 的内存 = 下载的字节(大约 60-100kb)+ 位图(140kb)+ 网络人员 + View 人员。我使用 Android Studio 中的内存分配跟踪确认了这一点。
因此,在堆增长之前,收集了一些没有引用的内存和对象(释放了270K,释放了119K,...),并且似乎只剩下Bitmap。
所以我的问题:
为什么即使当前 Activity 堆有大约 3000 kbytes 可用,Android 也无法分配 140 甚至 500 kbytes?
是否是特定设备或Android版本的问题?
最佳答案
Every decoded image is about 140-150 kbytes
这对于 ListView
行来说相当大,因为它相当于大约 390x390 的方形图像。
Why Android cannot allocate 140 or even 500 kbytes even if there is about 3000 kbytes free of current live heap?
因为“当前 Activity 堆中的 3000 KB 可用空间”在 Android 中是一个基本上没有意义的概念。您正在经历 GC_FOR_ALLOC
,因为没有足够大的可用内存块来满足您的请求。
引用myself ,为了便于阅读进行了少量编辑:
In Java, on the JVM, if there is no single block of memory big enough, that means that we are actually out of memory (with respect to this request, anyway).
However, the JVM has one thing that the Dalvik VM does not: a compacting garbage collector.
When we write programs in a language running on a runtime supporting garbage collection, we create a bunch of objects, and we later release some subset of those objects. The other ones we hold onto for a while, because we are still using them. In Android, for example, our
Application
, ourContentProvider
s, ourThread
s, our own static data members, and so on are going to live for quite some time, in many cases for the duration of the process. Anything they can reach also will not get garbage-collected. So, we allocate a bunch of memory and release some of that memory as our app runs.With a compacting garbage collector, the long-lived objects get slid around in memory, to allow the freed-up blocks of memory to be coalesced. The net is that all free heap space should be available as one contiguous block, eligible for allocation.
(the details are more complicated than that, but this is a Stack Overflow answer, not a dissertation)
With a non-compacting garbage collector, nothing is slid around in memory. We wind up with heap fragmentation, as what was once a pristine 16MB (or 32MB, or 48MB, or whatever) heap now is a bunch of objects with interspersed free memory. Even though we might have 10MB of free heap space, if the largest single block of that free heap space is only 1MB, we cannot allocate an 8MB
Bitmap
, because there is no free block big enough.The Dalvik VM has a non-compacting garbage collector.
请注意,ART (Android 5.0+) 有一个可以压缩的垃圾收集器,但仅当应用位于后台时才有效。
关于java - 每次加载图像时堆都会增长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32667821/
增长,则让
当我输入内容时,如何移动 p 段落下方的所有元素,即 contenteditable。 这是我的代码: body, html { margin: 0; padding: 0; backgr
我要解决的问题: 我有一个包含 div 的外部 div。 content 内部和外部 div 之间的边距应始终相同。 当内部 div 增长/收缩时,外部 div
这document Ulrich Drepper 称为“图书馆设计、实现和维护的良好实践”(第 5 页底部): [...] the type definition should always crea
有什么方法可以获取 QPainterPath 并将其展开,就像 Photoshop 中的“选择”>“增长...”(或“展开...”)命令一样? 我想获取从 QGraphicsItem::shape 返
假设,为了问题的目的,我们有一个内存池,最初分配了 n 个 block 。但是,当达到容量时,池想要增长并变成原来大小的两倍 (2n)。 现在可以使用 C 中的 realloc 完成此调整大小操作,但
假设,为了问题的目的,我们有一个内存池,最初分配了 n 个 block 。但是,当达到容量时,池想要增长并变成原来大小的两倍 (2n)。 现在可以使用 C 中的 realloc 完成此调整大小操作,但
我正在研究 boost 库的共享内存部分,为更大的项目做准备。我需要一个共享内存段,在初始化时我不一定知道它的大小,所以我的计划是增加这个段。 我的初始实现有一个存储在共享内存中的 boost::in
这个问题在这里已经有了答案: How to disable equal height columns in Flexbox? (4 个答案) What are the differences bet
我有一个包含子表的表。我不希望子表影响表格的宽度——在溢出的情况下,我希望两者独立滚动。此外,由于子表是基于切换显示的,所以我不希望主表行根据子表是否可见而跳转 Here's代码笔。 我想我可以用 t
我有一个带栏的页面设计,它可以有一个、两个或三个栏。这些列的大小应相同。 为此我使用了 flexbox,它很好,允许我添加/删除我的列并让浏览器处理列宽的大小调整。 现在,当列中的文本大于列的宽度时,
要求: 我需要根据数据增长一个任意大的数组。 我可以猜测大小(大约 100-200),但不能保证数组每次都能适合 一旦它增长到最终大小,我需要对其执行数值计算,因此我更愿意最终得到一个二维 numpy
我有一个 3x256 规则的规则集。每个规则映射到一个 3x3 的值网格,这些值本身就是规则。 规则示例: 0 -> [[0,0,0],[0,1,0],[0,0,0]] 1 -> [[1,1,1],
我有 3 个 div,如果我给前两个 div flex: 0.5,如果我给了 flex-wrap: wrap,最后一个 div 应该移动到下一行>。如果我错了,请指正。 以下是我的 html/css:
在文档和 Bootstrap v4 问题中 (here) ,我看不到任何支持 flex-grow 的计划,例如语法如下: I use all the space lef
要求: 我需要从数据中增加一个任意大的数组。 我可以猜测大小(大约 100-200),但不能保证每次都适合数组 一旦它增长到最终大小,我需要对其执行数值计算,因此我希望最终得到一个二维 numpy 数
我知道(并在互联网上阅读-包括此资源)。增加内存的逻辑是:如果len数组小于1024-golang将array乘以2,否则将len乘以1.25(并且我们在源代码中看到了这个问题https://gith
当输入长文本时,WPF TextBox 控件会增长。 这个问题已经在 Stackoverflow 中提出了 我也引用了一些答案,但我仍然没有找到有效的正确答案。 Here提到了同样的问题,但没有针对此
我在使用 Vaadin HorizonalLayout 时遇到问题 - 我希望左侧组件填充大部分水平空间,如 Fiddle 所示 但是,当我运行 Vaadin 应用程序时,这两个组件会平分屏幕。
关于这个fiddle , 当我点击 a href在这种情况下这是一个图像,我希望图像从 div 开始增长/过渡以通过过渡/缩放填充整个页面它被放置在其中。如果这不可能,我想用 div 的背景颜色填充页
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 6 年前。 Improve this q
我是一名优秀的程序员,十分优秀!