【问题标题】:Increase memory consumption after recreate activity重新创建活动后增加内存消耗
【发布时间】:2019-10-04 04:30:46
【问题描述】:

我的应用在这个活动(ViewPager)中有一个活动和 6 个片段,这个应用在正常使用中使用 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 和代码是什么?

谢谢。

【问题讨论】:

  • 您是否曾经在内存监视器中按“强制 gc”?您是否已经到了应用因 OOM 崩溃的地步?
  • 是的,我使用了一个计时器(5000 毫秒)来运行 System.gc(),但更改是明智的
  • 我的意思是内存监视器本身的强制 GC 按钮 (button 1 here),System.gc() 只是一个提示,大部分时间都被忽略了。
  • 没有太大区别,我测试过

标签: android android-studio memory-leaks


【解决方案1】:
  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.)

【讨论】:

  • 谢谢,很有帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-03-10
  • 2018-09-14
  • 2023-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多