Skip to content

Possible memory leak in AnimatorSetWrapper #28

@cmathew

Description

@cmathew

The following Magellan code would lead to a persisted Context reference:

  override fun onShow(context: Context, binding: LoadingSectionBinding) {
    ...
    blend {
      immediate()
      target(placeholderViews).animations {
        alpha(minAlpha)
      }
    }.then {
      stagger(subjects = placeholderViews, timeBetweenTargets = staggerStepMillis, timeUnit = MILLISECONDS) { currentView ->
        duration(time = pulseDurationMillis, timeUnit = MILLISECONDS)
        repeat(count = INFINITE, mode = REVERSE)
        target(currentView).animations {
          alpha(maxAlpha)
        }
      }
    }.start()
  }

  override fun onHide(context: Context, binding: LoadingSectionBinding) {
    ...
    blend.stopPulsing(*placeholderViews.toTypedArray())
  }

Avoiding the use of Blend's wrapper and using the Android animator directly fixes the leak:

  override fun onShow(context: Context, binding: LoadingSectionBinding) {
    ...
    animator = blend {
      immediate()
      target(placeholderViews).animations {
        alpha(minAlpha)
      }
    }.then {
      stagger(subjects = placeholderViews, timeBetweenTargets = staggerStepMillis, timeUnit = MILLISECONDS) { currentView ->
        duration(time = pulseDurationMillis, timeUnit = MILLISECONDS)
        repeat(count = INFINITE, mode = REVERSE)
        target(currentView).animations {
          alpha(maxAlpha)
        }
      }
    }.prepare()
    animator!!.start()
  }

  override fun onHide(context: Context, binding: LoadingSectionBinding) {
    animator!!.cancel()
    animator = null
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions