JNI ReferenceTable overflow泄露问题
INFO [ 225716.880557] (8065:11668) socket msgid:0
WARN [ 225716.880557] (8065:11669) dalvikvm ReferenceTable overflow (max=1024)
WARN [ 225716.880557] (8065:11669) dalvikvm JNI pinned array reference table (0x76292450) dump:
WARN [ 225716.880557] (8065:11669) dalvikvm Last 10 entries (of 1024):
WARN [ 225716.880557] (8065:11669) dalvikvm 1023: 0x44801458 byte[] (233 elements)
WARN [ 225716.880557] (8065:11669) dalvikvm 1022: 0x447be260 byte[] (233 elements)
WARN [ 225716.880557] (8065:11669) dalvikvm 1021: 0x44801908 byte[] (233 elements)
WARN [ 225716.880557] (8065:11669) dalvikvm 1020: 0x4476bb58 byte[] (233 elements)
WARN [ 225716.880557] (8065:11669) dalvikvm 1019: 0x44766680 byte[] (233 elements)
WARN [ 225716.880557] (8065:11669) dalvikvm 1018: 0x44744088 byte[] (128 elements)
WARN [ 225716.880557] (8065:11669) dalvikvm 1017: 0x44744348 byte[] (128 elements)
WARN [ 225716.880557] (8065:11669) dalvikvm 1016: 0x44778d38 byte[] (233 elements)
WARN [ 225716.880557] (8065:11669) dalvikvm 1015: 0x44833328 byte[] (233 elements)
WARN [ 225716.880557] (8065:11669) dalvikvm 1014: 0x44917c58 byte[] (233 elements)
ERROR [ 225716.880557] (8065:11668) PushConnection Get message exception
INFO [ 225716.880557] (8065:11668) PushConnection Receive err,errno:0
WARN [ 225716.880557] (8065:11669) dalvikvm Summary:
WARN [ 225716.880557] (8065:11669) dalvikvm 404 of byte[] (2 elements) (404 unique instances)
WARN [ 225716.880557] (8065:11669) dalvikvm 2 of byte[] (128 elements) (2 unique instances)
WARN [ 225716.880557] (8065:11669) dalvikvm 618 of byte[] (233 elements) (618 unique instances)
ERROR [ 225716.880557] (8065:11669) dalvikvm Failed adding to JNI pinned array ref table (1024 entries)
INFO [ 225716.880557] (8065:11669) dalvikvm "PushService-PushConnection-SendThread" prio=5 tid=14 RUNNABLE
INFO [ 225716.880557] (8065:11669) dalvikvm | group="main" sCount=0 dsCount=0 obj=0x4473b680 self=0x718111c0
INFO [ 225716.880557] (8065:11669) dalvikvm | sysTid=11669 nice=0 sched=0/0 cgrp=apps/bg_non_interactive handle=1904689136
INFO [ 225716.880557] (8065:11669) dalvikvm | state=R schedstat=( 4128488 1119325 30 ) utm=0 stm=0 core=3
Failed adding to JNI pinned array ref table (1024 entries),不能够将jni里指向的数组引用添加。再往上找看到关键的一句:ReferenceTable overflow (max=1024),经查是引用计数器溢出了,
最大为1024.即java的内存管理机制是基于引用的,需要计数器来记录引用的次数。在overflow这句话得后面当引用计数达到1024时还dump出了最近的10个引用。
这个时候需要在用到NewByteArray类似方法要使用setByteArrayRegion(),用GetByteArrayELement时要用ReleaseByteArrayElements来进行释放。
http://stackoverflow.com/questions/10383458/returning-jbytearray-from-native-c-in-android/10384585#10384585