堆外安卓的内存管理 [英] android memory management outside heap

查看:131
本文介绍了堆外安卓的内存管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Android应用程序和我们,因为我们有大量的图形,我们使用了大量的内存。

I am working on an application for android and we since we have lots of graphics, we use a lot of memory.

我监督为5Mb的内存堆的大小和它的约3-4 MB,而偷窥当我做一些事情,需要更多的内存(再回到3)。这不是一个大问题,但一些其他的东西是堆内存之外处理,如加载可绘制的。

I monitor the memory heap size and its about 3-4 Mb , and peeks of 5Mb when I do something that requires more memory (and then goes back to 3). This is not a big deal, but some other stuff is handled outside the heap memory, like loading of drawables.

例如,如果我运行Eclipse外DDMS工具,并转到SYSINFO,我看到我的应用程序正在和20MB的在Droid上12的G1,但是堆的大小是在两个相同的,因为数据是一样的但图像是不同的。

For example if I run the ddms tool outside eclipse, and go to sysinfo, I see that my app is taking 20Mb on the Droid and 12 on the G1, but heap size are the same in both, because data is the same but images are different.

所以,问题是: 我怎么知道该怎么走的是内存中的堆内存之外? 有什么其他的东西堆内存外需的内存?复杂的布局(大树)?动画?

So the questions are: How do I know what is taking the memory outside the heap memory? What other stuff takes memory outside the heap memory? Complex layouts (big tree) ? Animations?

感谢

丹尼尔

推荐答案

位图对象需要的内存相当很多

例。如果你的应用程序下载从净10KB JPG格式,并使用BitmapFactory脱$ C C是$成位图对象位图大概需要30-100KB内存,这取决于您的图像的分辨率。 3字节对于每个像素(1个字节为每个颜色)

Ex. if your app downloads a 10KB jpg from net and use BitmapFactory to decode it into a Bitmap that bitmap objects needs about 30-100KB memory, depending on the resolution of your image. 3bytes for each pixel (1 byte for each color)

是的,所有类型的对象使用的记忆,就像LinearLayouts,ImageViews等..如果您要创建和销毁许多对象,恩。当你在图片滚动/页,就会出现内存泄漏。气相色谱()不处理一样快,我们希望所谓的短命的对象。

And yes, all kind of object uses memory, like LinearLayouts, ImageViews etc... If you are creating and destroying many of these objects, ex. as you scroll / page through your images, there will be memory leaks. The gc() does not handle so-called short lived objects as fast as we would like.

保持视图对象的数量在稳定的水平的*,并回收销毁,并创造新的他们,而不是。

Keep the number of view objects at a stable level*, and recycle them instead of destroying and creating new ones.

REF: http://developer.android.com/resources/articles/轨道mem.html

如果您的应用程序达到20MB内存,它可能FC的BitmapFactory试图去$ C C下一图像$。

If your app reaches 20MB in memory, it may FC as the BitmapFactory is trying to decode the next image.

这篇关于堆外安卓的内存管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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