Eugen Martynov
Eugen Martynov

Reputation: 20140

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?

Upvotes: 8

Views: 2033

Answers (1)

Blackbelt
Blackbelt

Reputation: 157457

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.

Upvotes: 6

Related Questions