You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fun main(args: Array<String>) = runBlocking {
val scope = CoroutineScope(newSingleThreadContext("test"))
while (true) {
val job = scope.launch(start = CoroutineStart.ATOMIC) {
delay(Long.MAX_VALUE)
}
job.cancelAndJoin()
}
}
It creates newSingleThreadContext, then launches and cancels lots of coroutines that do delay(Long.MAX_VALUE) there. This code will end with OutOfMemoryError, because newSingleThreadContext uses ScheduleTheadPoolExecutor but cancelling scheduled tasks in it does not really work (memory is not really released until the trigger time). We'll need to rewrite newSingleThreadContext on top of a better thread-pool or use system-wide (default) delay implementation (aka DefaultExecutor) that does not suffer from this problem. We shall consider this problem in scope of #261.
The text was updated successfully, but these errors were encountered:
Consider the following code:
It creates
newSingleThreadContext
, then launches and cancels lots of coroutines that dodelay(Long.MAX_VALUE)
there. This code will end withOutOfMemoryError
, becausenewSingleThreadContext
usesScheduleTheadPoolExecutor
but cancelling scheduled tasks in it does not really work (memory is not really released until the trigger time). We'll need to rewritenewSingleThreadContext
on top of a better thread-pool or use system-wide (default) delay implementation (akaDefaultExecutor
) that does not suffer from this problem. We shall consider this problem in scope of #261.The text was updated successfully, but these errors were encountered: