Zum Inhalt springen

Coroutine Scope Never Cancelled (ARCH8034)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key kotlin.async.coroutine-scope-never-cancelled · Severity warning · Category async

Flags a CoroutineScope or Job created as a property that the class never cancels - every coroutine launched on it outlives the owner.

class Repo { private val scope = CoroutineScope(Dispatchers.IO) }
class Repo : Closeable {
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
override fun close() = scope.cancel()
}

Cancel the scope in close() / onCleared() / onDestroy(), or use a lifecycle-bound scope.