Skip to content

Commit

Permalink
Extract factories array to allow iterate on it to drop resources. Sho…
Browse files Browse the repository at this point in the history
…uld help fix #2058
  • Loading branch information
arnaudgiuliani committed Jan 9, 2025
1 parent 32095b4 commit eead325
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -159,13 +160,13 @@ class InstanceRegistry(val _koin: Koin) {
}

internal fun dropScopeInstances(scope: Scope) {
_instances.values.filterIsInstance<ScopedInstanceFactory<*>>().forEach { factory -> factory.drop(scope) }
val factories = _instances.values.toTypedArray()
factories.filterIsInstance<ScopedInstanceFactory<*>>().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()
}

Expand Down

0 comments on commit eead325

Please sign in to comment.