Android: Constant Memory Consumption / dumpGfxInfo()
2022-09-01 16:59:54
给定:使用Android Studio向导创建的简单活动,其中没有任何自定义代码,会消耗永久调用dumpGfxInfo()的内存。
Android Studio在 Allocation Tracker 中的构建显示,至少有三个线程在做同样的事情:
--- 8< ------------------------------------------------------------------
* < Thread 12 >
* execTransact():446, Binder (andoroid.os)
* onTransact():545, ApplicationThreadNative (android.app)
* dumpGfxInfo():1107, ActivityThread$ApplicationThread (android.app)
--- 8< -------------------------------------------------------------------
显然,dumpGfxInfo() 通过为空字符串分配内存来消耗内存。编译的唯一相关依赖项是 com.android.support:appcompat-v7:22.2.1
除了此内存消耗之外,还会出现以下异常(有时):
15331-15364/ W/Binder﹕ Caught a RuntimeException from the binder stub implementation.
java.lang.NullPointerException: Attempt to read from field 'android.view.HardwareRenderer android.view.View$AttachInfo.mHardwareRenderer' on a null object reference
at android.view.WindowManagerGlobal.dumpGfxInfo(WindowManagerGlobal.java:466)
at android.app.ActivityThread$ApplicationThread.dumpGfxInfo(ActivityThread.java:1107)
at android.app.ApplicationThreadNative.onTransact(ApplicationThreadNative.java:548)
at android.os.Binder.execTransact(Binder.java:446)
问题:如何修复/关闭此行为并摆脱它?