-
-
Notifications
You must be signed in to change notification settings - Fork 150
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 registerLazySingletonAsync
have a dependsOn
#339
Comments
please explain to me how lazy singletons prevent memory leeaks |
If I have a big app, with 100 Singletons, then if I don't use lazy Singleton factories, they will all be created as soon as the app starts. Many of those Singletons might only be useful on some parts of the app, parts that the user might not even use. With lazy singletons only the Singletons that are requested will be created and live in memory, thus reducing the memory footprint. |
That is true, but IMHO you take 1000s of Dart objects to get into memory troubles. Images are always the problem, not simple objects
Am 17. Aug. 2023, 16:22 +0200 schrieb Michel Feinstein ***@***.***>:
… If I have a big app, with 100 Singletons, then if I don't use lazy Singleton factories, they will all be created as soon as the app starts. Many of those Singletons might only be useful on some parts of the app, parts that the user might not even use. With lazy singletons only the Singletons that are requested will be created and live in memory, thus reducing the memory footprint.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
Yeah, but how do you know those singletons will always be simple objects? IMHO You agree with me that it can happen, you gave me examples when this is possible to happen, so why not make |
you also have to keep in mind, that I maintain several packages as the sole maintainer in my spare time. So I have to focus on feature requests that help a large group of my users and you are the first one since this package exists (and it's one of the oldest on pub) so it really doesn't seem to be a problem for the majority of my users. |
I think that's a fair point and I agree with you, my suggestion should not be dismissed based on personal opinions, but on technical matter, and should be implemented on a priority basis. |
First, I want to say I really like the package and appreciate the work that is put into packages like get_it. Thanks! Second, I would also appreciate such an enhancement. For my use-case, it's mainly that some singletons should be started in a specific order (which I can do with regular singletons and async ones, but not lazy singletons or even lazy async singletons) where they only work properly if some others are already setup (classic dependencies are API services, storage services and so on). In order to not overload everything on startup it would be nice to have the lazy loading feature in that situation as well. |
registerLazySingletonAsync
doesn't have adependsOn
, so we can't deal with more complex cases, where we want a lazy singleton, to avoid memory leaks, and also depend on another async singleton.The text was updated successfully, but these errors were encountered: