Android Studio Profiler 显示空活动的内存使用量为 100 MB
我正在使用 Android Studio Profiler 来检查和优化内存消耗。为了进行一些测试,我禁用了应用程序中除主要活动之外的每个部分。因此,当应用程序启动时,只有一个空白活动,它不执行任何操作,也不保留任何视图。然后,当我运行探查器时,它显示我的应用程序正在使用大约 100 MB
内存,其中一半用于本机代码。
此外,当我转储堆时,它仅显示 6.3 MB
的保留大小。这些数字让我很困惑!当我的 Activity 为空且未执行任何任务时,如何以及为何使用如此大量的内存 (100 MB)?
I'm using Android Studio Profiler to check and optimize memory consumption. to do some tests, I have disabled every section in the app except for the main activity. so when the app launches, there is only a blank activity which does not do anything and does not hold any view. then when I run the profiler, it shows about 100 MB
of memory is being used by my app, half of which is for native code.
Moreover, when I dump the heap, it shows only 6.3 MB
of retained size. these numbers confuse me! how and why such large amounts of memory (100 MB) are being used while my activity is empty and not doing any task?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
屏幕截图显示应用程序堆约为 6.3 MB。可能还有其他堆(单击“查看应用程序堆”菜单)。这些堆组合起来就是 JVM 正在使用的堆,它应该与分析器时间线中的“Java”类别一致。
要了解本机内存的用途,尝试 Android Studio 的 本机内存分析器。
当探查器与可调试进程一起使用时,它将在幕后执行操作,例如附加 JVMTI 代理。这些操作将占用本机内存。为了消除这些噪音,请考虑使用可分析的构建。 这里是构建可分析应用程序的说明,您需要 Android Studio Bumblebee在探查器中查看可分析的进程。
The screenshot shows the app heap is about 6.3 MB. There may be other heaps (clicking the "View app heap" menu). Those heaps combined are what the JVM is using, which should be consistent with the "Java" category from the profiler's timeline.
To find out what native memory is used for, it may be helpful to try Android Studio's native memory profiler during app startup.
When the profiler is used with a debuggable process, it will do things behind the scene, such as attaching a JVMTI agent. Those operations will occupy native memory. To eliminate those noise, please consider using a profileable build. Here is the instruction to build a profileable app, and you need Android Studio Bumblebee to view profileable processes in the profiler.