-
-
Notifications
You must be signed in to change notification settings - Fork 148
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
Make a lazy registerSingletonWithDependencies
#338
Comments
Can you explain to me how a lazy singleton would help you in this aspect? |
If we declare Singletons they will be create as soon as they are declared and will live in memory. Scopes allow us to reduce their footprint, but then we have to be controlling scopes all over the app. I don't want to use scopes for several reasons: 1 - I have a Let's say I have pages A, B, C, D and E. I want the same 2 - The less coupling my app has on third party libraries, the better. No offense, get_it is very useful, but I rather "contain" how much it influences my app in case I need to replace it one day. I declare the dependencies when the app starts and I make all the singletons and factories call each other. then I create the objects I want on a given page. This way I only have get_it in 2 places: App Initialization and Pages initialization. |
Honestly I m convinced that you will never have to worry about memory because you have too many singletonss in your app unless they cache images or other huge Dara blocks.
LazySingletons make sense if there initialisation take some time and we don't want to have done that all at startup.
I keep most of my manager objects as singletons that get initialid once on app startup.
Am 17. Aug. 2023, 16:16 +0200 schrieb Michel Feinstein ***@***.***>:
… If we declare Singletons they will be create as soon as they are declared and will live in memory. Scopes allow us to reduce their foot print, but then we have to be controlling scopes all over the app. I don't want to use scopes for several reasons:
1 - I have a Storage class that's used in many screens and flows in my app, but not in all of them. The ones who use it, I want them to have the same Singleton with the same internal cache. It's ok if it's created once by one screen and it lives there in memory, but I don't want to be micromanaging scopes the app.
2 - The less coupling my app has on third party libraries, the better. No offense, get_it is very useful, but I rather "contain" how much it influences my app in case I need to replace it one day. I declare the dependencies when the app starts and I make all the singletons and factories call each other. then I create the objects I want on a given page. This way I only have get_it in 2 places: App Initialization and Pages initialization.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
So you agree with me that are cases where Singletons can bloat your app's memory, so why not make the lib ready to provide to us the tools to control the memory in any way we want? |
See our other discussion |
If we have a Singleton that depends on another Singleton that has an
async
initialization, then we can't use lazy singletons, which leads to memory leaks.The text was updated successfully, but these errors were encountered: