Resource leaking can significantly impact the performance of an application, which is why it's important to release resources after using them. When we work with coroutines, we can just use the try {...} finally {...} block, even with long-term input/output operations.
The following example shows how we can use this block:
fun main(args: Array<String>) {
launch {
val fileReader = FileReader("path")
try {
delay(10000)
fileReader.read()
} finally {
fileReader.close()
}
}
}