Memory leak with Timer
问题 I am using a timer that is canceled and restarted on a listener event. It all works fine except that the the timer thread leaks the whole outer class. My timer implementation is as follows: if(timer != null) { timer.cancel(); timer = null; timer = new Timer(); } timer.schedule(new TimerTask() { // Thread leaks!!!! @Override public void run() { mCallback.onHeaderMoving(newToolbarTranslationY ); } } , 150); I used MAT Analyser to track down the problem and ended up there. I also commented out