CircularProgressBar icon indicating copy to clipboard operation
CircularProgressBar copied to clipboard

Memory leak if you set `indeterminateMode` on detached view

Open AChep opened this issue 3 years ago • 0 comments

When you set the indeterminateMode to true you spawn a handler that continuously updates the state of the progress bar.

    var indeterminateMode = false
        set(value) {
            field = value
            onIndeterminateModeChangeListener?.invoke(field)
            progressIndeterminateMode = 0f
            progressDirectionIndeterminateMode = ProgressDirection.TO_RIGHT
            startAngleIndeterminateMode = DEFAULT_START_ANGLE

            indeterminateModeHandler?.removeCallbacks(indeterminateModeRunnable)
            progressAnimator?.cancel()
            indeterminateModeHandler = Handler()

            if (field) {
                indeterminateModeHandler?.post(indeterminateModeRunnable)
            }
        }

The problem is that this handler gets cleared only in onDetachedFromWindow. Hence you get the leak if the view was never attached.

AChep avatar Dec 03 '20 20:12 AChep