Does Android View.postDelayed leak reference?

android, handler, view

Solution

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.

Problem

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?

Original source