rxdroid icon indicating copy to clipboard operation
rxdroid copied to clipboard

Activity memory leak caused by the anonymous thread

Open cuixiaoyiyi opened this issue 2 years ago • 0 comments

An anonymous inner class will hold a reference to the this pointer of the outer class and will not be released until the thread ends. It will hold the Activity and prevent its timely release.

In DrugListActivity2.java, there is a timed task. It can be improved by TimerTask elegantly and efficiently.

timer = 
timerTask = timerTask(){
  run(){
  }
}
timer.schedule(timerTask,10,1100);

onDestroy(){
 timer.cancel();
}

cuixiaoyiyi avatar Aug 29 '22 08:08 cuixiaoyiyi