我正在使用UIautomator为我们的Android应用程序运行高容量使用测试。经过一段时间后,我得到了大量对android.view.RenderNode的弱全局引用,导致应用程序崩溃。对我来说,看起来它与android.view.View类的内部部分有关。我想知道是否有办法在达到表限制之前清理这些弱全局引用。这是一个痕迹:
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] JNI ERROR (app bug): weak global reference table overflow (max=51200)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] weak global reference table dump:
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] Last 10 entries (of 51200):
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 51199: 0x1ad5e2f8 android.view.RenderNode
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 51198: 0x1ad5e118 android.view.RenderNode
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 51197: 0x1ad56fe8 android.view.RenderNode
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 51196: 0x1ad56fb8 android.view.RenderNode
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 51195: 0x1ad56f88 android.view.RenderNode
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 51194: 0x1ad56ce8 android.view.RenderNode
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 51193: 0x1ad56868 android.view.RenderNode
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 51192: 0x1ad56688 android.view.RenderNode
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 51191: 0x1ad565c8 android.view.RenderNode
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 51190: 0x1ad56598 android.view.RenderNode
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] Summary:
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 1 of org.chromium.android_webview.AwQuotaManagerBridge
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 3 of byte[] (2016 elements) (3 unique instances)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 3 of byte[] (6864 elements) (3 unique instances)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 1 of byte[] (7392 elements)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 1 of byte[] (9408 elements)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 5 of byte[] (12544 elements) (5 unique instances)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 4 of byte[] (13720 elements) (4 unique instances)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 1 of byte[] (22500 elements)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 1 of byte[] (23520 elements)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 9 of byte[] (28224 elements) (9 unique instances)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 1 of byte[] (32592 elements)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 27 of byte[] (36100 elements) (27 unique instances)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 10 of byte[] (37632 elements) (10 unique instances)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 2 of byte[] (47432 elements) (2 unique instances)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 2 of byte[] (48400 elements) (2 unique instances)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 19 of byte[] (50176 elements) (19 unique instances)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 3 of byte[] (63504 elements) (3 unique instances)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 2 of byte[] (64512 elements) (2 unique instances)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 3 of byte[] (108192 elements) (3 unique instances)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 4 of byte[] (112896 elements) (4 unique instances)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 4 of byte[] (147000 elements) (4 unique instances)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 1 of byte[] (178084 elements)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 2 of byte[] (179776 elements) (2 unique instances)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 5 of byte[] (367236 elements) (5 unique instances)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 2 of byte[] (1666560 elements) (2 unique instances)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 6 of dalvik.system.PathClassLoader (2 unique instances)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 16 of java.lang.DexCache (16 unique instances)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132] 51062 of android.view.RenderNode (51062 unique instances)
04-06 10:42:05.205 F/art ( 4806): art/runtime/indirect_reference_table.cc:132]
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] Runtime aborting...
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] Aborting thread:
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] "main" prio=10 tid=1 Runnable
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] | group="" sCount=0 dsCount=0 obj=0x75986698 self=0xb088b400
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] | sysTid=4806 nice=-10 cgrp=default sched=0/0 handle=0xb4c25534
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] | state=R schedstat=( 0 0 0 ) utm=2324 stm=4003 core=0 HZ=100
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] | stack=0xbf0bd000-0xbf0bf000 stackSize=8MB
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] | held mutexes= "abort lock" "JNI weak global reference table lock" "mutator lock"(shared held)
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] native: #00 pc 00572f6e /system/lib/libart.so (_ZN3art15DumpNativeStackERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEEiP12BacktraceMapPKcPNS_9ArtMethodEPv+238)
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] native: #01 pc 0053f35e /system/lib/libart.so (_ZNK3art6Thread9DumpStackERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEEbP12BacktraceMap+526)
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] native: #02 pc 0053c35b /system/lib/libart.so (_ZNK3art6Thread4DumpERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEEbP12BacktraceMap+75)
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] native: #03 pc 00527f13 /system/lib/libart.so (_ZNK3art10AbortState10DumpThreadERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEEPNS_6ThreadE+67)
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] native: #04 pc 00527bca /system/lib/libart.so (_ZNK3art10AbortState4DumpERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEE+330)
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] native: #05 pc 0051822b /system/lib/libart.so (_ZN3art7Runtime5AbortEPKc+155)
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] native: #06 pc 0011a5b3 /system/lib/libart.so (_ZN3art10LogMessageD1Ev+1747)
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] native: #07 pc 002cd198 /system/lib/libart.so (_ZN3art22IndirectReferenceTable3AddEjPNS_6mirror6ObjectE+376)
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] native: #08 pc 0039323b /system/lib/libart.so (_ZN3art9JavaVMExt16AddWeakGlobalRefEPNS_6ThreadEPNS_6mirror6ObjectE+91)
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] native: #09 pc 00403b64 /system/lib/libart.so (_ZN3art3JNI16NewWeakGlobalRefEP7_JNIEnvP8_jobject+788)
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] native: #10 pc 0013f952 /system/lib/libart.so (_ZN3art8CheckJNI6NewRefEPKcP7_JNIEnvP8_jobjectNS_15IndirectRefKindE+1106)
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] native: #11 pc 001396c9 /system/lib/libart.so (_ZN3art8CheckJNI16NewWeakGlobalRefEP7_JNIEnvP8_jobject+57)
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] native: #12 pc 000c2541 /system/lib/libandroid_runtime.so (???)
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] native: #13 pc 00af872c /system/framework/x86/boot-framework.oat (Java_android_view_RenderNode_nCreate__Ljava_lang_String_2+136)
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] at android.view.RenderNode.nCreate(Native method)
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] at android.view.RenderNode.<init>(RenderNode.java:137)
04-06 10:42:05.316 F/art ( 4806): art/runtime/runtime.cc:422] at android.view.RenderNode.create(RenderNode.java:161)
04-06 10:42:05.317 F/art ( 4806): art/runtime/runtime.cc:422] at android.view.View.<init>(View.java:4026)
04-06 10:42:05.317 F/art ( 4806): art/runtime/runtime.cc:422] at android.view.View.<init>(View.java:4146)
04-06 10:42:05.317 F/art ( 4806): art/runtime/runtime.cc:422] at android.widget.TextView.<init>(TextView.java:710)
04-06 10:42:05.317 F/art ( 4806): art/runtime/runtime.cc:422] at android.widget.TextView.<init>(TextView.java:704)
04-06 10:42:05.317 F/art ( 4806): art/runtime/runtime.cc:422] at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:76)
04-06 10:42:05.317 F/art ( 4806): art/runtime/runtime.cc:422] at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:72)
04-06 10:42:05.317 F/art ( 4806): art/runtime/runtime.cc:422] at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
04-06 10:42:05.317 F/art ( 4806): art/runtime/runtime.cc:422] at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1016)
04-06 10:42:05.317 F/art ( 4806): art/runtime/runtime.cc:422] at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1073)
04-06 10:42:05.317 F/art ( 4806): art/runtime/runtime.cc:422] at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:769)
04-06 10:42:05.317 F/art ( 4806): art/runtime/runtime.cc:422] at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
04-06 10:42:05.317 F/art ( 4806): art/runtime/runtime.cc:422] at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
04-06 10:42:05.317 F/art ( 4806): art/runtime/runtime.cc:422] at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
04-06 10:42:05.317 F/art ( 4806): art/runtime/runtime.cc:422] at android.view.LayoutInflater.rInflate(LayoutInflater.java:861)
04-06 10:42:05.317 F/art ( 4806): art/runtime/runtime.cc:422] at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
04-06 10:42:05.317 F/art ( 4806): art/runtime/runtime.cc:422] at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
04-06 10:42:05.317 F/art ( 4806): art/runtime/runtime.cc:422] - locked <0x0e863a9a> (a java.lang.Object[])
04-06 10:42:05.317 F/art ( 4806): art/runtime/runtime.cc:422] at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
04-06 10:42:05.317 F/art ( 4806): art/runtime/runtime.cc:422] at android.view.LayoutInflater.inflate(LayoutInflater.java:377) ...
答案 0 :(得分:1)
除非您真的需要超过51200个实例,否则很有可能正在泄漏android.view.View
个实例?这是一些强制错误并演示限制的简单代码:
new Thread() {
HashSet<View> aLotOfViews = new HashSet<>();
@Override
public void run() {
Log.d("test", "Hi, I need a lot of views");
for (int i = 0; i < 59000; i++) {
aLotOfViews.add(new View(getApplicationContext()));
if (i % 1000 == 0) {
Log.d("test", "I have some views: " + aLotOfViews.size());
}
}
Log.d("test", "I have a lot of views: " + aLotOfViews.size());
}
}.start();
我建议尝试使用Google的内存分析工具来查找泄漏:https://developer.android.com/studio/profile/memory-profiler