Feature Request: Allow instances to be reused, but also garbage collected
It's great that we have some flexibility between factory and singleton!
At the same time, we have many classes that could be reused if they already exist, without a strong need to only have one single instance.
- With
singleton, we find ourselves wasting memory by retaining such classes far beyond when we need them - With
factory, we find ourselves wasting memory by creating too many simultaneous instances of classes that could have be shared
It would be great if we could tell Koin to
- reuse an existing instance if it already has one, but also
- give Koin the freedom to let that instance be garbage collected whenever it's no longer needed and recreated in the future
This is similar to Dagger's @Reusable scope.
Yep, something like with weak references to garbage it if nobody has nay reference on it 🤔
Any plans on when this will get added? It's been 1y+
Swinject already has this feature as well and I believe it is a must-have, otherwise we would need to be hacking around scopes.
yes, it's something that need a bit of rework for internal engine