Android : OutOfMemoryError by using java.util.Timer

on Wednesday, August 13, 2014



Timer mTimer;

void scheduleSyncIn(int aSeconds){
if (mTimer != null) {
mTimer.cancel();
mTimer = null;
}
mTimer = new Timer();
TimerTask task = new TimerTask() {

@Override
public void run() {
// call a method
}
};

if (request) {
mTimer.schedule(task, aSeconds * 1000);
}
}


from this i got the following report from play store



java.lang.OutOfMemoryError: pthread_create (stack size 16384 bytes) failed: Try again
at java.lang.VMThread.create(Native Method)
at java.lang.Thread.start(Thread.java:1029)
at java.util.Timer$TimerImpl.<init>(Timer.java:192)
at java.util.Timer.<init>(Timer.java:367)
at java.util.Timer.<init>(Timer.java:387)
at java.util.Timer.<init>(Timer.java:394)
at com.example.Manager.scheduleSyncIn(Manager.java:66)
at com.example.Manager.scheduleSync(Manager.java:56)
at com.example.Manager.RequestDone(Manager.java:180)
com.example.Manager.Remote$GetMetaData.onPostExecute(Remote.java:338)
at com.example.Manager.Remote$GetMetaData.onPostExecute(Remote.java:1)
at android.os.AsyncTask.finish(AsyncTask.java:632)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5137)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
at dalvik.system.NativeStart.main(Native Method)


now i don't know why this error while i am cancel the timer and free it for GC every time before initialize. Thanks for any help.


0 comments:

Post a Comment