重新创建活动后增加内存消耗

时间:2019-05-16 20:39:17

标签: android android-studio memory-leaks

我的应用程序有一个活动,并且该活动有6个片段(ViewPager),该应用程序在正常使用情况下使用120MB的内存,当我关闭该应用程序并重新打开时,内存消耗将增加(最大为200MB),这将随着只要我这样做。

我尝试过: 1-使用后回收位图 2-取消注册OnDestroy()中的侦听器 3- Runtime.getRuntime()。gc() ...

Android Studio探查器(首次创建活动): 码:21.5 MB 图形38.7 MB 本机:14.4 MB 爪哇:42.5 MB 其他:4 MB

问题: 1-我该怎么办? 2-什么是探查器中的图形,Java和代码?

谢谢。

1 个答案:

答案 0 :(得分:0)

  1. 有很多原因,可能是因为内存泄漏。如果有泄漏,GC将无济于事。
    下一步,详细分析。就像转储内存一样。
    https://developer.android.com/studio/profile/memory-profiler?hl=en

有一个库可以帮助您检测泄漏。 https://github.com/square/leakcanary

  1. 有关内存探查器的第一个链接还描述了什么是“图形”。
Graphics: Memory used for graphics buffer queues to display pixels to the screen, including GL surfaces, GL textures, and so on.
(Note that this is memory shared with the CPU, not dedicated GPU memory.)