Hi I'm using the following code so in the event of a crash recycle will always be called to free up the memory.
context.obtainStyledAttributes(attrs, R.styleable.example).apply {
try {
getDrawable(R.styleable.example_drawable)
} finally {
recycle()
}
}
However, for some reason in android studio lint cannot detect the recycle call and it always complains, giving me this warning:
This 'TypedArray' should be recycled after use with '#recycle()'
I also tried using a Kotlin extension function which should automatically call recycle for me:
context.obtainStyledAttributes(attrs, R.styleable.example).use
{
it.getDrawable(R.styleable.example_drawable)
}
But the lint warning still persists. Any idea what to do?
I am currently using latest versions of Android Studio, Gradle, and Kotlin (3.5.2, 6.0.1, and 1.3.60 respectively)
Is there a way to update lint maybe? Or does it already come with Android Studio.? Thanks.
*Edit: It seems the .apply is part of the problem. Removing that or the try finally block removes the warning, so somehow you can't have both at the same time. Is this a bug..?