Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Difference between lazySingleton and singleton in Get_it

Currently, I am using get_it package for dependency injection. However, I have confused about singleton and lazySingleton.

I know its difference is lazySingleton will not init until it’s used and reduce init time as well as saving resource. However, I don’t know what is drawbacks of lazySinglton with singleton are. Why not replace all singleton with lazySingleton.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Both are Singletons. But LazySingleton refers to a class whose resource will not be initialised until it’s used for the 1st time. It’s generally used to save resources and memory.

Now the drawback, LazySingleton will take time when it is used for the first time. the other singleton may have been initialized in advance and the time taken to initialize might have been used to make the process faster.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading