Skip to content

Commit

Permalink
Fix bitmap leak.
Browse files Browse the repository at this point in the history
  • Loading branch information
pokercc committed Dec 14, 2021
1 parent cae086b commit f0c611b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class AnimationActivity : AppCompatActivity() {
Dp(0f).toPx().toFloat(),
Dp(20f).toPx().toFloat()
)
anim?.cancel()
cancelAnim()
val animatorSet = AnimatorSet()
anim = animatorSet
animatorSet.duration = 2000
Expand All @@ -89,12 +89,20 @@ class AnimationActivity : AppCompatActivity() {
super.onStart()
anim?.resume()
}

override fun onPause() {
super.onPause()
anim?.pause()
}

override fun onDestroy() {
super.onDestroy()
cancelAnim()
}

private fun cancelAnim() {
anim?.removeAllListeners()
anim?.cancel()
anim = null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,9 @@ internal abstract class BitmapShadowDrawable(shadowPath: Path) : ShadowDrawable(

abstract fun onDrawBitmap(bitmap: Bitmap)

override fun release() {
bitmap?.recycle()
bitmap = null
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ class BoxShadowLayout @JvmOverloads constructor(
tellParentNotChip()
}

override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
shadowDrawable.release()
}

override fun draw(canvas: Canvas) {
drawShadow(canvas)
val saveCount = canvas.saveLayer(null, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ internal abstract class ShadowDrawable(protected val shadowPath: Path) : Drawabl
open fun invalidateCache() = Unit

abstract fun onShadowChange(blur: Float, color: Int, inset: Boolean)

open fun release() = Unit
}

0 comments on commit f0c611b

Please sign in to comment.