我目前正在编写一个应用程序,我主要使用一个活动。 This is the component tree.
我在上面两个图像视图中使用两个屏幕宽度和大约300px高图像,最低的一个是纯色面板。除此之外,该应用程序还创建了大约15个带矢量背景的按钮,大小约为42dp。这些按钮没有点击监听器,我已经为它们关闭了stateListAnimator。它们不能作为正确的按钮运行,但是例如用textView替换它们并没有解决问题。
我还将48个声音文件加载到SoundPool中,每个文件的单个大小为8,57 KB。我尝试不加载这些文件,但这并没有以任何重要的方式改变RAM的使用。
我将minifyEnabled设置为true,这些是我的依赖项:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.android.support:customtabs:28.0.0-rc02'
implementation 'com.android.support:support-v4:28.0.0-rc02'
implementation 'com.android.support:support-media-compat:28.0.0-rc02'
implementation 'com.android.support:animated-vector-drawable:28.0.0-rc02'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:preference-v7:28.0.0-rc02'
implementation 'com.google.android.gms:play-services-ads:15.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
我现在的问题是,这个应用程序虽然似乎没有任何泄漏,但从一开始就占用了大量的内存。它因设备而异,但通常在70mb到130mb之间。 Here is a shot of the Android profiler.
不使用广告有轻微的影响,但没有什么太疯狂,如here所见。
所以在这一点上,我不完全确定可能导致问题的原因以及我可以采取哪些步骤来解决这个问题。所以我希望这里有人可以提供帮助。
如果需要我忘记的任何其他信息,我会提供。谢谢。
检查你的图像的大小可能其中一个有一个大尺寸,并尝试优化你的xml代码,这可能是你的应用程序使用大量RAM的原因。并检查“LeakCanary”它对RAM有很大帮助