Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible memory leak in AnimatorSetWrapper #28

Open
cmathew opened this issue May 31, 2023 · 0 comments
Open

Possible memory leak in AnimatorSetWrapper #28

cmathew opened this issue May 31, 2023 · 0 comments

Comments

@cmathew
Copy link
Contributor

cmathew commented May 31, 2023

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
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant