Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Android View.postDelayed leak reference?

I wonder if runnable passed to View.postDelayed will be automatically removed when the view is detached from the parent.

I looked in the source of the View class and it is posted to some Handler that it gets outside. But life cycle of that handler is not clear.

Does anyone know the answer?

like image 501
Eugen Martynov Avatar asked Oct 31 '16 10:10

Eugen Martynov


1 Answers

I wonder if runnable passed to View.postDelayed will be automatically removed when the view is detached from the parent.

It will after the run method finishes to execute. If you have a infinite loop into it, it will never be removed and, therefore, you will leak the view, and the Activity that uses that view.

like image 97
Blackbelt Avatar answered Nov 20 '22 04:11

Blackbelt