android - How/when is a Handler garbage collected? -


inside class of mine have following code:

mhandler = createhandler();  private handler createhandler() {     return new handler() {         public void handlemessage (message msg) {             update();             if (!paused) {                 sendemptymessagedelayed(0, 300);             }         }     }; } 

the documentation says:

http://developer.android.com/reference/android/os/handler.html

each handler instance associated single thread , thread's message queue

so if understood correctly handler not garbage collected long application thread running, correct?

in specific example since handler anonymous inner class has implicit reference enclosing object , whole hierarchy of objects pointed it. looks me recipe memory leaking.

btw, can make handler stop sending messages(that's why have if (!paused)) won't make gced, right?

so there way remove handler message queue , gced?

in specific example since handler anonymous inner class has implicit reference enclosing object , whole hierarchy of objects pointed it.

you reduce impact of potential leak nothing using static nested class instead of anonymous inner class.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -