Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Allow instances to be reused, but also garbage collected #1378

Open
ankushg opened this issue Jul 7, 2022 · 3 comments
Open
Assignees
Labels
core status:checking currently in analysis - discussion or need more detailed specs type:feature-proposal
Milestone

Comments

@ankushg
Copy link

ankushg commented Jul 7, 2022

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.

@arnaudgiuliani arnaudgiuliani self-assigned this Aug 26, 2022
@arnaudgiuliani arnaudgiuliani added the status:checking currently in analysis - discussion or need more detailed specs label Aug 26, 2022
@arnaudgiuliani
Copy link
Member

Yep, something like with weak references to garbage it if nobody has nay reference on it 🤔

@arnaudgiuliani arnaudgiuliani modified the milestones: 3.3.0, 4.0.0 Aug 26, 2022
@lcszc
Copy link

lcszc commented Oct 3, 2023

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.

@arnaudgiuliani
Copy link
Member

yes, it's something that need a bit of rework for internal engine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core status:checking currently in analysis - discussion or need more detailed specs type:feature-proposal
Projects
None yet
Development

No branches or pull requests

3 participants