为什么正常的画面分配大量的内存? [英] Why does the normal pictures allocated a lot of memory?

查看:127
本文介绍了为什么正常的画面分配大量的内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中使用较少的内存,它是关于3.4MB,在一些老的Andr​​oid设备,如GT-I9001。但是当我的HTC One运行它,我的应用程序使用非常多的内存。

My application use a little memory, it's about 3.4MB, in some old android devices such as GT-I9001. But when i running it in HTC one, my application use very more memory.

看,分配的内存为26.881MB,它太大,可用内存只有2.940MB。然后使用MAT工具检查内存泄漏,我找了位图资源的使用马赫内存。

Look, the allocated memory is 26.881MB, it's too big, and the free memory only have 2.940MB. Then i use MAT tool check the memory leak, i find the resource bitmap use mach memory.

我无法解释的原因。我经常出内存的应用程序。我想也许问题是由高屏幕分辨率造成的。如果有人也遇到这个问题,请加入讨论,谢谢!

I can't explain the reason. My application often out of memory. I think Maybe the problem is caused by high screen resolution. If someone also encountered this problem, please join the discussion, thanks!

我debuged问题,并发现了一些原因:

I debuged the problem, and found some reason:

本的onCreate()函数我做起的活动,你可以看到断点。该应用程序只调用的setContentView(R.layout.welcome)加载XML布局使用前分配的内存3.4MB。然后应用程序运行到下一个步骤,它使用分配的内存19MB。所以我觉得这个问题也必须通过加载XML布局造成的。

The onCreate() function in my start activity, and you can see the breakpoint. The application only use allocated memory 3.4MB before calling the setContentView(R.layout.welcome) to load layout xml. Then the application run to next step, it use allocated memory 19MB. So i think this problem must be caused by loading the layout xml.

我体改了的welcome.xml文件,删除了所有部件,即只有一个RelativeLayout的

I modifed the "welcome.xml" file, deleted all widgets, that only have a "RelativeLayout"

但程序也使用19MB内存。最后,我删除的RelativeLayout的背景与程序存储器恢复到正常大小,它只能使用3MB。

But the program also use 19MB memory. Finally, i deleted the backgroud of RelativeLayout and the program memory return to normal size, it only use 3MB.

礼品编号的loading_background.png大小只有21KB,我想,也许高端设备的高屏幕分辨率在内存中修改图片大小,我会尝试使用9.png图片。如果你了解这部分问题,请加入讨论,谢谢!

The size of pictrue "loading_background.png" is only 21KB, i think that perhaps the high screen resolution of high-end device changed the picture size in memory, i will try to use 9.png picture. If you understand this part of the problem, please join the discussion, thanks!

推荐答案

此问题可以通过绘制-nodpi来解决,看看这个:

This problem can be solved using drawable-nodpi, look this:

Android的背景图像内存使用

这篇关于为什么正常的画面分配大量的内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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