So, I have this function:
inline fun runInLoop(intervalInMillis : Long = 1_000, crossinline function : suspend () -> Unit) {
CoroutineScope(Dispatchers.Main).launch {
while (true) {
function.invoke()
delay(intervalInMillis)
}
}
}
And I use it like so:
Time.runInLoop(10_000L) {
binding.timeCreatedTextView.text = mContext.getString(R.string.time_created,
Time.unixToRelativeTime(item.timeCreated))
}
Basically, I use this function to loop every one second to refresh "timeCreatedTextView"s with DateUtils.getRelativeTimeSpanString(), and that is used the most in RecyclerView rows, so multiple infinite loops will be running on a coroutine in the background.
My question is, is anything that I'm doing potential source for memory leaks or high memory usages, since I'm using DateUtils to get the relative time, or doing string formatting every one second for however long the view is on screan?