From eead32584b12407b29edff92dac85a7a9447ad65 Mon Sep 17 00:00:00 2001 From: Arnaud Giuliani Date: Thu, 9 Jan 2025 16:43:26 +0100 Subject: [PATCH] Extract factories array to allow iterate on it to drop resources. Should help fix #2058 --- .../kotlin/org/koin/core/registry/InstanceRegistry.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/projects/core/koin-core/src/commonMain/kotlin/org/koin/core/registry/InstanceRegistry.kt b/projects/core/koin-core/src/commonMain/kotlin/org/koin/core/registry/InstanceRegistry.kt index f5476761c..036f0b0db 100644 --- a/projects/core/koin-core/src/commonMain/kotlin/org/koin/core/registry/InstanceRegistry.kt +++ b/projects/core/koin-core/src/commonMain/kotlin/org/koin/core/registry/InstanceRegistry.kt @@ -34,6 +34,7 @@ import org.koin.core.qualifier.Qualifier import org.koin.core.scope.Scope import org.koin.core.scope.ScopeID import org.koin.mp.KoinPlatformTools.safeHashMap +import kotlin.collections.toTypedArray import kotlin.reflect.KClass @Suppress("UNCHECKED_CAST") @@ -159,13 +160,13 @@ class InstanceRegistry(val _koin: Koin) { } internal fun dropScopeInstances(scope: Scope) { - _instances.values.filterIsInstance>().forEach { factory -> factory.drop(scope) } + val factories = _instances.values.toTypedArray() + factories.filterIsInstance>().forEach { factory -> factory.drop(scope) } } internal fun close() { - _instances.forEach { (_, factory) -> - factory.dropAll() - } + val factories = _instances.values.toTypedArray() + factories.forEach { factory -> factory.dropAll() } _instances.clear() }