Spot the bug
Which line allocates on every frame?
class Gauge(context: android.content.Context) : android.view.View(context) {private val paint = android.graphics.Paint()var value = 0foverride fun onDraw(canvas: android.graphics.Canvas) {val rect = android.graphics.RectF(0f, 0f, width * value, height.toFloat())canvas.drawRect(rect, paint)}}
Hint 1 of 1
Which object is created inside onDraw?
Choose an answer, then open Show answer below to check it.
Show answer
- Answer: line 5
val rect = android.graphics.RectF(0f, 0f, width * value, height.toFloat())
Line 5 creates a new RectF every time onDraw runs, which can be 60 or more times a second. Keep one RectF as a field and update it with set().