Will this code cause a memory leak if it is present in the Activity VS ViewModel component?
handlerThread = new HandlerThread("myHandlerThread");
handlerThread.start();
Handler handler = new Handler(handlerThread.getLooper());
handler.postDelayed(new Runnable() {
@Override
public void run() {
//Do work
}
}, 1000);
@Override
protected void onDestroy() {
super.onDestroy();
handlerThread.quit();
}
Will replacing the anonymous runnable class with a static class that extends Runnable make any difference? This was mentioned @4:13 in this video tutorial!
Why would an anonymous runnable hold reference to an Activity or ViewModel?