Kiki Abdullah
02/27/2022, 4:46 AMTypedArray
should be recycled after use with `#recycle()`` after use obtainTypedArray
for my array list. But when I try to call recycle()
, getResourceId()
show unresolved reference
error.Kiki Abdullah
02/27/2022, 4:47 AMprivate val listUsers: ArrayList<User>
get() {
val userName = resources.getStringArray(R.array.name)
val userUserName = resources.getStringArray((R.array.username))
val userAvatar = resources.obtainTypedArray(R.array.avatar)
val listUser = ArrayList<User>()
for (i in userName.indices) {
val user = User(userName[i], userUserName[i], userAvatar.getResourceId(i, -1))
listUser.add(user)
}
return listUser
}
zsmb
02/27/2022, 11:29 AMobtainTypedArray
method returns a TypedArray
, which has to be recycled when you no longer need it. In your case, this means that you should call userAvatar.recycle()
once you're done using that object - probably between the for
loop and the return
statement.Kiki Abdullah
02/27/2022, 11:37 AMuserAvatar.recycle()
inside the for loop just after listUser.add(user)
statement?zsmb
02/27/2022, 1:11 PMrecycle
after you're completely done using the array. If you use it in the for loop on each iteration, call it after the loop is done.