java - Reference table overflow caused by SimpleDateFormat.format() -


i have android project , there's activity need display current time on screen. used working thread post message main thread handler once per second. , in handler, format current time , display on ui. got reference table overflow problem after running every 30 mins, , program crashed error. here's log:

referencetable overflow (max=1024) jni pinned array reference table (0x6080b458) dump:   last 10 entries (of 1024):      1023: 0x423b76d0 int[] (1 elements)      1022: 0x4209cea0 int[] (1 elements)      1021: 0x4209c890 int[] (1 elements)      1020: 0x42242198 int[] (1 elements)      1019: 0x421b7b60 int[] (1 elements)      1018: 0x420c0e08 int[] (1 elements)      1017: 0x42107c18 int[] (1 elements)      1016: 0x421078e8 byte[] (1 elements)      1015: 0x42116a18 int[] (1 elements)      1014: 0x42116408 int[] (1 elements)   summary:         1 of byte[] (1 elements)      1023 of int[] (1 elements) (1023 unique instances) failed adding jni pinned array ref table (1024 entries) "main" prio=5 tid=1 runnable   | group="main" scount=0 dscount=0 obj=0x417f5de0 self=0x417e44a8   | systid=7820 nice=0 sched=0/0 cgrp=apps handle=1074331988   | state=r schedstat=( 0 0 0 ) utm=972 stm=228 core=0   @ libcore.icu.nativedecimalformat.formatlong(native method)   @ libcore.icu.nativedecimalformat.formatlong(nativedecimalformat.java:253)   @ java.text.decimalformat.format(decimalformat.java:684)   @ java.text.numberformat.format(numberformat.java:299)   @ java.text.decimalformat.format(decimalformat.java:702)   @ java.text.simpledateformat.appendnumber(simpledateformat.java:785)   @ java.text.simpledateformat.append(simpledateformat.java:676)   @ java.text.simpledateformat.formatimpl(simpledateformat.java:553)   @ java.text.simpledateformat.format(simpledateformat.java:818)   @ java.text.dateformat.format(dateformat.java:307)   @ com.tuyou.tsd.launcher.sleepingactivity.updatetime(sleepingactivity.java:206)   @ com.tuyou.tsd.launcher.sleepingactivity.access$1(sleepingactivity.java:204)   @ com.tuyou.tsd.launcher.sleepingactivity$2.handlemessage(sleepingactivity.java:66)   @ android.os.handler.dispatchmessage(handler.java:102)   @ android.os.looper.loop(looper.java:136)   @ android.app.activitythread.main(activitythread.java:5146)   @ java.lang.reflect.method.invokenative(native method)   @ java.lang.reflect.method.invoke(method.java:515)   @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:732)   @ com.android.internal.os.zygoteinit.main(zygoteinit.java:566)   @ dalvik.system.nativestart.main(native method) vm aborting fatal signal 6 (sigabrt) @ 0x00001e8c (code=-6), thread 7820 (com.tuyou.tsd) 

i noticed crash happened in simpledateformat.format() method call. looking source code, found method implement by

return format(date, new stringbuffer(), new fieldposition(0)).tostring(); 

so i'm wondering possible stringbuffer , fieldposition caused memory leak? or program running fast object can't clean soon, caused objects in ref table? here's implement codes:

public class sleepingactivity extends baseactivity { … private timetask mtimetask = null; private simpledateformat mdateformat = new simpledateformat("hh:mm", locale.china); private date mcurrenttime = new date(); …  private handler mhandler = new handler(looper.getmainlooper()) {     @override     public void handlemessage(message msg) {         switch (msg.what) {         case 100:             updatetime();             break;         default:             super.handlemessage(msg);         }     } };  private void updatetime() {     mcurrenttime.settime(system.currenttimemillis());     string time = mdateformat.format(mcurrenttime); // problem happened here!     if (mtimeview != null) {         mtimeview.settext(time);     } }  private class timetask extends thread {     private boolean stop;      @override     public void run() {         looper.getmainlooper();         while (!stop) {             message msg = message.obtain(null, 100);             mhandler.sendmessage(msg);             try { thread.sleep(1000); } catch (interruptedexception e) {}         }     }    } …  } 

please help… thx.

=========================================================== edit: trying find root cause, comment out of lines in updatetime(), after running still 30 mins. got reference table overflow error, seems different before.

referencetable overflow (max=1024) jni pinned array reference table (0x60865460) dump:   last 10 entries (of 1024):      1023: 0x42269d20 int[] (1 elements)      1022: 0x42269478 int[] (1 elements)      1021: 0x42262e50 int[] (1 elements)      1020: 0x42262dc0 int[] (1 elements)      1019: 0x42262d28 byte[] (1 elements)      1018: 0x4225d800 int[] (1 elements)      1017: 0x42258af0 int[] (1 elements)      1016: 0x42256940 int[] (1 elements)      1015: 0x422535d0 int[] (1 elements)      1014: 0x42251390 int[] (1 elements)   summary:         1 of byte[] (1 elements)      1023 of int[] (1 elements) (1023 unique instances)  failed adding jni pinned array ref table (1024 entries) "binder_3" prio=5 tid=24 runnable   | group="main" scount=0 dscount=0 obj=0x42151ee0 self=0x60ae8008   | systid=5507 nice=0 sched=0/0 cgrp=apps handle=1627171640   | state=r schedstat=( 0 0 0 ) utm=2 stm=1 core=0   @ android.os.parcel.nativeenforceinterface(native method)   @ android.os.parcel.enforceinterface(parcel.java:451)   @ android.app.applicationthreadnative.ontransact(applicationthreadnative.java:383)   @ android.os.binder.exectransact(binder.java:404)   @ dalvik.system.nativestart.run(native method) vm aborting 

i found root cause of problem. it's nothing java methods, it's 1 of jni function call, used

(*env)->getbytearrayelements(env,buf, null) 

to allocate array, didn't release after use. after running 30 mins, ref table overflow. added

(*env)->releasebytearrayelements(env, buf, buf_char, jni_abort); 

the problem never happened again.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -