Android的图片缓存 - 怎么样?缓存、图片、Android

由网友(我嫉妒你身边每一个无关紧要的人,他们就那样轻而易举见到我朝思)分享简介:我觉得是问及问过了,不过,有件事情我不是很了解。我已经尝试了两种不同的方式:保存在内存中的所有图像,开始时一定限度的超越,开始删除它们让Android的解决这个问题有SoftReferences 在2.它只是清除它们有时第二个我分配他们!我不分配太多 - 30-40图片50×50像素所以,我坚持一个。现在的问题是什...

我觉得是问及问过了,不过,有件事情我不是很了解。

我已经尝试了两种不同的方式:

保存在内存中的所有图像,开始时一定限度的超越,开始删除它们 让Android的解决这个问题有SoftReferences

在2.它只是清除它们有时第二个我分配他们!我不分配太多 - 30-40图片50×50像素

所以,我坚持一个。现在的问题是什么是极限?

在我能得到多少完全位内存设备的一些可靠的信息我已经离开?我做了一些调查,看DDMS价值,它只是占用了越来越多的空间,直到它爆炸(如果我不清理)。这一刻,只有200K左右,明年该系统提供2M更多... 在我目前使用的启发式决策,根据设备型号,或屏幕大小。我认为这是死胡同,从长远来看。得到了内存不足异常在某些手机上,完全免费等。 是否有第三种解决方案,是正确的? 解决方案

最重要的问题:您循环() -ing您的位图?这是pre-姜饼应用程序(也许后姜饼太)。

非常重要

看着的 for Android应用程序内存管理的会议从谷歌I / O 2011 帮助我更好地理解为Android开发的特殊性。

这是视频中提到了一个名为 MAT 工具 - 一个内存分析器 - 这是有用为确定是否有对象已泄漏的内存徘徊。这可能是你有一个以上的30-40你认为你有。

Android之清理缓存

有关查看和/或记录堆的电流大小,等等,我建议使用code在this回答有关Android的内存不足异常的。

I think it is asked and asked before, but still, there are things I can't quite understand.

I have tried two different approaches:

Keep all the images in memory, when certain limit is started to exceed, start removing them Let Android fix this with SoftReferences

In 2. it's just cleaning them up sometimes the second I allocate them! And I don't allocate too much - 30-40 images 50x50 pixels.

So I am sticking to one. The question is what is the limit?

Can I get some reliable info from the device of how much exactly bitmap memory do I have left? I have done some research, watch DDMS values, it's just taking up more and more space (if I don't clean up) until it explodes. One moment there are only 200K left, next the system provides 2M more... I am currently using some heuristic decision, based on device model, or screen size. I think this is dead-end in the long run. Got memory exceptions on some phones, completely free on other. Is there a third solution, the right one?

解决方案

Most important question: Are you recycle()-ing your bitmaps? This is very important for pre-Gingerbread applications (maybe post-Gingerbread too).

Watching the Memory Management for Android Apps session from Google I/O 2011 helped me get a better understanding of the peculiarities of developing for Android.

That video mentions a tool called MAT - a Memory Analyzer - which is useful for determining if you have objects hanging around in memory that have been leaked. It's possibly you have more than the 30-40 you think you have.

For viewing and/or logging the current size of heap, etc., I'd suggest using the code in this answer about Android Out of Memory exceptions.

阅读全文

相关推荐

最新文章