java - Would anonymous Handler or Runnable create a memory leak? -
new handler().postdelayed(new runnable(){ @override public void run() { // stuff }}, 100);
if call activity (oncreate or onresume or elsewhere) can cause memory leak? i've read new runnable()
should static instance, true?
yes. code may cause memory leak.
for long anonymous class based on runnable
in queue (100 milliseconds in example), keeps reference outer activity
class.
such memory leak not problem of course, depending on code inside run
executed, may create bigger problems, crashing application when e.g. try show dialog after activity
killed. in such situations see nice informational exceptions:
illegalargumentexception: can not perform action after onsaveinstancestate
or
badtokenexception: unable add window - ... activity running?
Comments
Post a Comment