gpt4 book ai didi

java - 布局中的内存分配

转载 作者:太空狗 更新时间:2023-10-29 15:17:22 24 4
gpt4 key购买 nike

在我的项目中,我有一个由单个 XML 布局组成的简单 Activity (由 setContentView 启用)。不过,该项目还有其他 Activity 。

布局基本上由两个 .jpg 图像组成。第一个有 25kB,大小为 400x153 像素。第二个有 4kB,150x50 像素。

尽管上下文非常简单,DDMS 告诉我我有 13MB 分配给我的程序,我认为这是巨大的,因为我只加载了两个小图像,并且某些设备每个程序的最大堆大小为 16MB .

这种布局堆这么大正常吗?

编辑:HProf 转储:

Problem Suspect 1: The class "android.content.res.Resources", loaded by "", occupies 9,429,232 (70.39%) bytes. The memory is accumulated in one instance of "java.lang.Object[]" loaded by "".

Problem Suspect 2: 3 instances of "android.graphics.Bitmap", loaded by "" occupy 2,147,960 (16.03%) bytes.

Biggest instances:
•android.graphics.Bitmap @ 0x41407b98 - 1,048,648 (7.83%) bytes.
•android.graphics.Bitmap @ 0x4169e6a0 - 979,256 (7.31%) bytes.

我真的不能解释这个。但是好像我的其他资源是预先加载的? (在我进入各自的 Activity 之前?)

最佳答案

如果您说这就是您的程序试图做的所有事情,那么这很正常。位图确实占用大量内存。尝试优化您的图像,这肯定会帮助您减少应用程序的内存占用。在创建背景时考虑 9 补丁图像。

关于java - 布局中的内存分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11572896/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com